Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. /**
  2.  * Created by steve on 22/06/17.
  3.  */
  4. import org.openqa.selenium.By;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.chrome.ChromeDriver;
  8. import org.openqa.selenium.chrome.ChromeOptions;
  9. import org.openqa.selenium.support.ui.ExpectedConditions;
  10. import org.openqa.selenium.support.ui.WebDriverWait;
  11. import org.testng.Assert;
  12. import org.testng.annotations.AfterClass;
  13. import org.testng.annotations.BeforeClass;
  14. import org.testng.annotations.Test;
  15.  
  16. public class GoogleHomePageTest {
  17.  
  18.     private WebDriver driver;
  19.     String appURL = "https://www.google.com.ar";
  20.     protected String GOOGLE_TITLE= "Google";
  21.     protected String GOOGLE_INPUT_ID = "lst-ib";
  22.     protected String GOOGLE_SEARCH_BUTTTON = "_fZl";
  23.     protected By WIKIPEDIA_LINK = By.xpath("//div[@id='rso']/div/div/div/div/div/h3/a");
  24.     protected String WIKIPEDIA_TITLE ="Cats - Wikipedia, la enciclopedia libre";
  25.     protected String WORDS_TO_SEARCH_IN_GOOGLE= "CATS";
  26.  
  27.  
  28.     @BeforeClass
  29.     // Setting chromedriver driver
  30.     public void testSetUp() {
  31.         // Call chromedriver.
  32.         System.setProperty("webdriver.chrome.driver", "/home/steve/Documents/CURSOS/CURSOS_EXTERNO/swd/chromedriver");
  33.         //Disable barInfo
  34.         ChromeOptions options = new ChromeOptions();
  35.         options.addArguments("disable-infobars");
  36.         driver = new ChromeDriver(options);
  37.     }
  38.     @Test
  39.     // Ejecuting Test
  40.     public void verifyWikepediaPageTittle() {
  41.         //Open Google
  42.         driver.get(appURL);
  43.         //Verify Google Title
  44.         String getTitle = driver.getTitle();
  45.         Assert.assertEquals(getTitle, GOOGLE_TITLE);
  46.         //Fill out search input
  47.         driver.findElement(By.id(GOOGLE_INPUT_ID)).sendKeys(WORDS_TO_SEARCH_IN_GOOGLE);
  48.         //Press search button
  49.         driver.findElement(By.id(GOOGLE_SEARCH_BUTTTON)).click();
  50.         //Wait till GOOGLE_IMAGES_LINK is present
  51.         WebDriverWait wait = new WebDriverWait(driver, 10);
  52.         WebElement element = wait.until(ExpectedConditions.elementToBeClickable(WIKIPEDIA_LINK));
  53.         //Press search button
  54.         driver.findElement(WIKIPEDIA_LINK).click();
  55.         //Verify Wikipedia Title
  56.         getTitle = driver.getTitle();
  57.         Assert.assertEquals(getTitle, WIKIPEDIA_TITLE);
  58.     }
  59.  
  60.     @AfterClass
  61.     // Closing Browser when finish the test
  62.     public void tearDown() {
  63.         //driver.quit();
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement