Monday, May 12, 2014

Working with WebDriver

In this Post, we shall:
‹‹ Run a test with Firefox
‰‰ Working with Firefox profiles
‹‹ Run a test with Google Chrome or Chromium
‰‰ Updating the capabilities of the browser
‹‹ Run a test with Opera
‰‰ Working with Opera Profiles
‹‹ Run a test with Internet Explorer
‰‰ Working with Internet Explorer Driver
So let's get on with it...



Working with FirefoxDriver

FirefoxDriver is the easiest driver to use, since everything that we need to use is all bundled
with the Java client bindings that we used in the previous chapter.
In the next section we are going to see about loading the browser and typing to the screen.
This is what we will be doing in most of our applications.

We are going to do the basic task of loading the browser and type into the page.
1. Update the setUp() method to load the FirefoxDriver();
driver = new FirefoxDriver();
2. Now we need to find an element. In this section we will find the one with
the ID nextBid:
WebElement element = driver.findElement(By.id("nextBid"));
3. Now we need to type into that element:
element.sendKeys("100");
4. Run your test and it should look like the following:
public class TestChapter6 {
WebDriver driver;
@Before
public void setUp(){
driver = new FirefoxDriver();
driver.get("http://book.theautomatedtester.co.uk/chapter4");
}
@After
public void tearDown(){
driver.quit();

Working with WebDriver


}
@Test
public void testExamples(){
WebElement element = driver.findElement(By.id("nextBid"));
element.sendKeys("100");
}

}


A lot of people like to use Firebug with WebDriver but get really annoyed with the First
Run page.
1. To get around this, we are going to have to update the version of Firebug in your
Firefox Preferences.
2. We will set the version to 99.9:
public class TestChapter6 {
WebDriver driver;
@Before
public void setUp(){
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension("firebug.xpi");
profile.setPreference("extensions.firebug.currentVersion",
"99.9");
driver = new FirefoxDriver(profile);
driver.get("http://book.theautomatedtester.co.uk/chapter4");
}
@After
public void tearDown(){
driver.quit();
}
@Test
public void testExamples(){
WebElement element = driver.findElement(By.id("nextBid"));
element.sendKeys("100");
}

}

No comments:

Post a Comment