Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.41 KB | None | 0 0
  1. package alexx;
  2.  
  3.  
  4. import org.openqa.selenium.WebElement;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.firefox.FirefoxDriver;
  7. import static org.junit.Assert.*;
  8. import org.junit.After;
  9. import org.junit.Before;
  10. import org.junit.Test;
  11. import org.openqa.selenium.By;
  12. import org.openqa.selenium.WebDriver;
  13. import org.openqa.selenium.firefox.FirefoxDriver;
  14.  
  15. public class course3 {
  16.  
  17.     System.setProperty("webdriver.gecko.driver", "C:\\Users\\dv6\\Desktop\\SELENIUM\\librairieseleniumpourcode\\geckodriver-v0.11.0-win32\\geckodriver.exe");
  18.     WebDriver driver;
  19.    
  20.     @Before
  21.      public void setUp() {
  22.          //1. open the browser
  23.          driver = new FirefoxDriver();
  24.     }
  25.  
  26.     @After
  27.        public void tearDown() {
  28.         Thread.sleep(5000);
  29.         driver.quit();
  30.     }
  31.  
  32.     @Test
  33.     public void test1() {
  34.         //2. open the home page of the site in the browser
  35.         driver.get("http://www.vpl.ca");
  36.  
  37.         //3. search for a keyword (Java)
  38.  
  39.         WebElement searchField;
  40.  
  41.         searchField = driver.findElement(By.xpath("//input[@id='globalQuery']"));
  42.  
  43.         searchField.click();
  44.  
  45.         searchField.sendKeys("java");
  46.        
  47.         WebElement searchButton;
  48.        
  49.         searchButton = driver.findElement(By.xpath("//input[@class='search_button']"));
  50.        
  51.         searchButton.click();
  52.        
  53.         Thread.sleep(5000);
  54.        
  55.         //4. on the results page, select the first search result
  56.        
  57.         WebElement searchResultLink;
  58.        
  59.         searchResultLink = driver.findElement(By.xpath("(//a[@testid='bib_link'])[1]"));
  60.        
  61.         searchResultLink.click();
  62.        
  63.         Thread.sleep(5000);
  64.  
  65.         //5. on the result details page, the result title is displayed
  66.        
  67.         WebElement bookTitleElement;
  68.        
  69.         bookTitleElement = driver.findElement(By.xpath("//h1[@testid='text_bibtitle']"));
  70.        
  71.         assertEquals(bookTitleElement.isDisplayed(), true);
  72.        
  73.         /*
  74.         if (bookTitleElement.isDisplayed() == true){
  75.        
  76.             System.out.println("the first book name is displayed on the page");
  77.         }
  78.        
  79.         else{
  80.        
  81.             System.out.println("the first book name is NOT displayed on the page");
  82.         }
  83.        
  84.         //6. on the result details page, the result author is displayed
  85.        
  86.         WebElement bookAuthorElement = driver.findElement(By.xpath("//a[@testid='author_search']"));
  87.        
  88.         if (bookAuthorElement.isDisplayed() == true){
  89.        
  90.             System.out.println("the first book author is displayed");
  91.         }
  92.        
  93.         else{
  94.        
  95.             System.out.println("the first book author is NOT displayed");
  96.         }
  97.         */
  98.        
  99.     }
  100.        
  101.        
  102.     @Test
  103.     public void test2() {
  104.             //2. open the home page of the site in the browser
  105.             driver.get("http://www.vpl.ca");
  106.  
  107.             //3. search for a keyword (Java)
  108.  
  109.             WebElement searchField;
  110.  
  111.             searchField = driver.findElement(By.xpath("//input[@id='globalQuery']"));
  112.  
  113.             searchField.click();
  114.  
  115.             searchField.sendKeys("java");
  116.            
  117.             WebElement searchButton;
  118.            
  119.             searchButton = driver.findElement(By.xpath("//input[@class='search_button']"));
  120.            
  121.             searchButton.click();
  122.            
  123.             Thread.sleep(5000);
  124.            
  125.             //4. on the results page, select the first search result
  126.            
  127.             WebElement searchResultLink;
  128.            
  129.             searchResultLink = driver.findElement(By.xpath("(//a[@testid='bib_link'])[1]"));
  130.            
  131.             searchResultLink.click();
  132.            
  133.             Thread.sleep(5000);
  134.  
  135.             //5. on the result details page, the result title is displayed
  136.            
  137.                
  138.             WebElement bookAuthorElement;
  139.             bookAuthorElement = driver.findElement(By.xpath("//a[@testid='author_search'])[1]"));
  140.             assertEquals(bookAuthorElement.isDisplayed(), true);
  141.        
  142.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement