我想测试一个web应用程序,它以输入作为参数并生成输出。我不想做加载或压力测试,我希望有大约100个用户输入参数并点击提交。我们怎么能把这事自动化呢?
我想测试的web应用程序是http://protein.rnet.missouri.edu:8080/MongoTest/。
发布于 2015-04-27 06:26:34
您可以通过使用HtmlUnit实现这样的功能。
HtmlUnit是一个“无GUI浏览器的Java程序”。它对HTML文档进行了建模,并提供了一个API,允许您调用页面、填写表单、单击链接等。就像你在“普通”浏览器里做的一样。
这样做的方法如下:
//set browser
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10);
//not to throw exception on javascript error
webClient.setThrowExceptionOnScriptError(false);
//set page to access
final HtmlPage homepageEn = webClient.getPage("http://protein.rnet.missouri.edu:8080/MongoTest/");
//get the form by id
HtmlForm form = homepageEn.getFirstByXPath("//form[@id='input_form']");
//setup the fields to use
HtmlTextInput mailField = form.getInputByName("mail");
HtmlPasswordInput passwordField = form.getInputByName("password");
//define the submit button (defined by value)
HtmlSubmitInput submitButton = form.getInputByValue("submit");
//change the value of text fields
mailField.setValueAttribute("somemail@xyzmail.com");
passwordField.setValueAttribute("some_password");
//finally submit the form by clicking the button
final HtmlPage resultsPage = submitButton.click();然后,您可以实现这100个用户,可能使用一个循环或其他什么。这完全取决于你..。
希望这能帮上忙。
https://stackoverflow.com/questions/29883779
复制相似问题