Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most efficient way of filling in details on a web form?

Tags:

webdriver

Take a standard web page with lots of text fields, drop downs etc. What is the most efficient way in webdriver to fill out the values and then verify if the values have been entered correctly.

like image 575
rhanabe Avatar asked Aug 08 '12 09:08

rhanabe


2 Answers

You only have to test that the values are entered correctly if you have some javascript validation or other magic happening at your input fields. You don't want to test that webdriver/selenium works correctly.

There are various ways, depending if you want to use webdriver or selenium. Here is a potpourri of the stuff I'm using.

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"));

With webdriver only:

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"));
like image 134
VolkerK Avatar answered Oct 21 '22 18:10

VolkerK


Hopefully, the results of filling out your form are visible to the user in some manner. So you could think along these BDD-esque lines:

When I create a new movie
Then I should see my movie page

That is, your "new movie" steps would do the field entry & submit. And your "Then" would assert that the movie shows up with your entered data.

element = driver.find_element(:id, "movie_title")
element.send_keys 'The Good, the Bad, the Ugly'
# etc.
driver.find_element(:id, "submit").click

I'm just dabbling in this now, but this is what I came up with so far. It certainly seems more verbose than something like Capybara:

fill_in 'movie_title', :with => 'The Good, the Bad, the Ugly'

Hope this helps.

like image 2
Jon Kern Avatar answered Oct 21 '22 18:10

Jon Kern