Selenium 如何将对象作为参数传递给Html单元驱动程序
我必须用Html单元驱动程序测试一个网页,但是当我得到一个没有传递类对象作为参数的网页时,我收到了一个错误 这是html代码:Selenium 如何将对象作为参数传递给Html单元驱动程序,selenium,unit-testing,htmlunit,Selenium,Unit Testing,Htmlunit,我必须用Html单元驱动程序测试一个网页,但是当我得到一个没有传递类对象作为参数的网页时,我收到了一个错误 这是html代码: <form name="fund_form" id="fund_form" th:action="@{/save-fund}" th:object="${fund}" method="post"> <input type="hidden" th:field="*{id_fund}"> <in
<form name="fund_form" id="fund_form" th:action="@{/save-fund}"
th:object="${fund}" method="post">
<input type="hidden" th:field="*{id_fund}"> <input
type="hidden" th:value="${activeId}" th:name="owner" th:id="owner" />
<input type="hidden" th:value="${0}" th:name="money" th:id="money" />
<input type="hidden" th:value="${1}" th:name="state" th:id="state" />
<textarea rows="3" cols="45" th:field="*{subject}" maxlength="135" form="fund_form" required></textarea>
<br>
<input type="submit"
name="btn_save_fund" value="Insert NEW FUND!">
在这里,我将活动用户(@modeldattribute User)作为参数传递给myFunds方法,该方法使用插入的资金重新加载页面
现在我必须测试文本区域和按钮
这是测试的代码:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class FundWebControllerIT {
@Autowired
FundRepo fundRepo;
@LocalServerPort
private int port;
private WebDriver driver;
private String baseURL;
@Before
public void setUp() throws Exception {
baseURL = "http://localhost:" + port;
driver = new HtmlUnitDriver();
fundRepo.deleteAll();
fundRepo.flush();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
//method to test (when I should pass an "user" obj as parameter
@Test
public void testInsertNewFund() {
driver.get(baseURL + "/my-funds");
driver.findElement(By.id("subject")).sendKeys("test fund");
driver.findElement(By.name("btn_save_fund")).click();
}
}
当我运行测试时,出现以下错误:
java.lang.NullPointerException: null
at
com.crowdfunding.controller.ApplicationWebController.myFunds(ApplicationWebController.java:50)~[classes/:na]
在com.crowdfunding.controller.ApplicationWebController.ActionMyFunds(ApplicationWebController.java:104)~[classes/:na]
这是因为
return myFunds(model, user);
是空的
如何在HTML单元测试中传递对象作为参数
谢谢
return myFunds(model, user);