以一个有很多文本字段、下拉列表等的标准网页为例,在webdriver中填充值的最有效方法是什么,然后验证值是否输入正确。
发布于 2012-08-09 18:30:27
如果您在输入字段中进行了一些javascript验证或其他魔术操作,则只需测试输入的值是否正确。您不希望测试webdriver/selenium是否正常工作。
有多种方法,这取决于您想使用webdriver还是selenium。这是我正在使用的东西的一个大杂烩。
Assert.assertEquals("input field must be empty", "", selenium.getValue("name=model.query"));
driver.findElement(By.name("model.query")).sendKeys("Testinput");
//here you have to wait for javascript to finish. E.g wait for a css Class or id to appear
Assert.assertEquals("Testinput", selenium.getValue("name=model.query"));仅使用webdriver:
WebElement inputElement = driver.findElement(By.id("input_field_1"));
inputElement.clear();
inputElement.sendKeys("12");
//here you have to wait for javascript to finish. E.g wait for a css Class or id to appear
Assert.assertEquals("12", inputElement.getAttribute("value"));发布于 2013-07-10 00:43:06
希望用户能够以某种方式看到填写表单的结果。因此,您可以按照BDD风格的思路来思考:
When I create a new movie
Then I should see my movie page也就是说,您的“新电影”步骤将完成字段输入和提交。你的"Then“会断言电影是用你输入的数据显示的。
element = driver.find_element(:id, "movie_title")
element.send_keys 'The Good, the Bad, the Ugly'
# etc.
driver.find_element(:id, "submit").click我现在只是在涉足这一点,但这是我到目前为止想出来的。它看起来肯定比像Capybara这样的东西更冗长:
fill_in 'movie_title', :with => 'The Good, the Bad, the Ugly'希望这能有所帮助。
https://stackoverflow.com/questions/11861680
复制相似问题