About Selenium Web driver
Selenium is UI and function testing tools so we test our web site ,web application using selenium.Selenium is open source tools Download here
Now let we discuss about selenium web driver.
Selenium WebDriver is the successor to Selenium RC. Selenium WebDriver accepts commands (sent in Selenese, or via a Client API) and sends them to a browser. This is implemented through a browser-specific browser driver, which sends commands to a browser, and retrieves results. Most browser drivers actually launch and access a browser application
Requirment
Linux ,windows ,Eclipse for java ,Visual studio for C#(Nunit tools for test C# test case)
Step
1.Download Rc server Jar files
2. Start eclipse
3.File >> New Java Projects
4.Create Class
5.Build path>> Configure Path >>Add Libraries>> Junit
6.Build path>> Configure Path >>Add Externals Jar>> seleinum jar
7. Write A Test Case in a Class
8, Test case Run as Junit
Code:
public class Test {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://excilysbank.aws.af.cm/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws Exception {
driver.get(baseUrl + "/public/login.html");
driver.findElement(By.id("username")).sendKeys("user1");
driver.findElement(By.id("password")).sendKeys("password1");
driver.findElement(By.cssSelector("input.button.blue")).click();
driver.findElement(By.linkText("PERSONNAL_CHECKING")).click();
driver.findElement(By.linkText("November")).click();
driver.findElement(By.linkText("December")).click();
driver.findElement(By.linkText("January")).click();
driver.findElement(By.linkText("February")).click();
driver.findElement(By.linkText("Log out")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
Functional Testing With Selenium
Assertion is the technique to compare the test result .
There are 2 way to assert the text in Web Driver.
Performance Testing With Jmeter
Selenium is UI and function testing tools so we test our web site ,web application using selenium.Selenium is open source tools Download here
Now let we discuss about selenium web driver.
Selenium WebDriver is the successor to Selenium RC. Selenium WebDriver accepts commands (sent in Selenese, or via a Client API) and sends them to a browser. This is implemented through a browser-specific browser driver, which sends commands to a browser, and retrieves results. Most browser drivers actually launch and access a browser application
Requirment
Linux ,windows ,Eclipse for java ,Visual studio for C#(Nunit tools for test C# test case)
Step
1.Download Rc server Jar files
2. Start eclipse
3.File >> New Java Projects
4.Create Class
5.Build path>> Configure Path >>Add Libraries>> Junit
6.Build path>> Configure Path >>Add Externals Jar>> seleinum jar
7. Write A Test Case in a Class
8, Test case Run as Junit
Code:
public class Test {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://excilysbank.aws.af.cm/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws Exception {
driver.get(baseUrl + "/public/login.html");
driver.findElement(By.id("username")).sendKeys("user1");
driver.findElement(By.id("password")).sendKeys("password1");
driver.findElement(By.cssSelector("input.button.blue")).click();
driver.findElement(By.linkText("PERSONNAL_CHECKING")).click();
driver.findElement(By.linkText("November")).click();
driver.findElement(By.linkText("December")).click();
driver.findElement(By.linkText("January")).click();
driver.findElement(By.linkText("February")).click();
driver.findElement(By.linkText("Log out")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
Functional Testing With Selenium
Assertion is the technique to compare the test result .
There are 2 way to assert the text in Web Driver.
1.driver.getPageSource().contains("String") 2.WebElement el = driver.findElement(By.xpath("xpath"));Example: Code: public void test() throws Exception {
driver.get(baseUrl + "/public/login.html");
driver.getPageSource().contains("Welcome to Excilys Bank"); WebElement el = driver.findElement(By.xpath("/html/body/div/div/div[2]"));
Thread.sleep(3000);
driver.findElement(By.id("username")).sendKeys("user1");
driver.findElement(By.id("password")).sendKeys("password1");
driver.findElement(By.cssSelector("input.button.blue")).click();
}Or public void test() throws Exception {
driver.get(baseUrl + "/public/login.html");
WebElement el = driver.findElement(By.xpath("/html/body/div/div/div[2]"));
Thread.sleep(3000);
driver.findElement(By.id("username")).sendKeys("user1");
driver.findElement(By.id("password")).sendKeys("password1");
driver.findElement(By.cssSelector("input.button.blue")).click();driver.getPageSource().contains("Welcome to Excilys Bank"); After run ,it searching the text "Welcome to Excilys Bank" in complete page if text is getting then it pass this test and script is continue else getting error on the script.Performance Testing With Jmeter
No comments:
Post a Comment