Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package selenium.web.driver;
- import static org.junit.Assert.assertTrue;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
- public class OMS_selenium_Test {
- WebDriver driver;
- WebElement element;
- @Before
- public void setUp() throws Exception {
- driver = new FirefoxDriver();
- driver.get("http://localhost:8180/OMS/login.htm");
- // precondition
- element = driver.findElement(By.name("j_username"));
- element.sendKeys("login1");
- element = driver.findElement(By.name("j_password"));
- element.sendKeys("qwerty");
- element.submit();
- // waiting
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- System.out.println("InterruptedException occured");
- }
- // going to ordering page
- driver.get("http://localhost:8180/OMS/order.htm");
- }
- @Test
- public void test_Status_Delivered() {
- // choose Status from search drop down list
- driver.findElement(By.xpath("//option[@value='orderStatus']")).click();
- // choose Delivered from criteria to Status
- driver.findElement(By.xpath("//option[@value='Delivered']")).click();
- // click Apply button
- driver.findElement(By.name("Apply")).click();
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- System.out.println("InterruptedException occured");
- }
- // checking results
- String actualResultOne = driver.findElement(By.xpath("//DIV[@id = 'list']//TABLE//TR//TD[.//text()[starts-with(., 'OrderName1')]]")).getText();
- String actualResultTwo = driver.findElement(By.xpath("//DIV[@id = 'list']//TABLE//TR//TD[.//text()[starts-with(., 'OrderName5')]]")).getText();
- assertTrue("Test run successefull", actualResultOne.equals("OrderName1") && actualResultTwo.equals("OrderName5"));
- }
- @Test
- public void test_SearchBy_OrderName() {
- // choose OrderName from search drop down list
- driver.findElement(By.xpath("id('search')/option[@value='orderName']")).click();
- // enter value into field
- element = driver.findElement(By.name("searchValue"));
- element.sendKeys("OrderName1");
- // click Apply button
- driver.findElement(By.name("Apply")).click();
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- System.out.println("InterruptedException occured");
- }
- // compare results
- String actualResult = driver.findElement(By.xpath("//DIV[@id = 'list']//TABLE//TR//TD[.//text()[starts-with(., 'OrderName1')]]")).getText();
- assertTrue("Test run successefull", actualResult.equals("OrderName1"));
- }
- @After
- public void tearDown() throws Exception {
- // log out
- element = driver.findElement(By.xpath("//UL[@id = 'nav']//LI[contains(concat(' ', @class, ' '), ' spec ')]//A[contains(concat(' ', @class, ' '), ' spec ')]"));
- // quit browser
- driver.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement