Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package alexx;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import static org.junit.Assert.*;
- 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.firefox.FirefoxDriver;
- public class course3 {
- System.setProperty("webdriver.gecko.driver", "C:\\Users\\dv6\\Desktop\\SELENIUM\\librairieseleniumpourcode\\geckodriver-v0.11.0-win32\\geckodriver.exe");
- WebDriver driver;
- @Before
- public void setUp() {
- //1. open the browser
- driver = new FirefoxDriver();
- }
- @After
- public void tearDown() {
- Thread.sleep(5000);
- driver.quit();
- }
- @Test
- public void test1() {
- //2. open the home page of the site in the browser
- driver.get("http://www.vpl.ca");
- //3. search for a keyword (Java)
- WebElement searchField;
- searchField = driver.findElement(By.xpath("//input[@id='globalQuery']"));
- searchField.click();
- searchField.sendKeys("java");
- WebElement searchButton;
- searchButton = driver.findElement(By.xpath("//input[@class='search_button']"));
- searchButton.click();
- Thread.sleep(5000);
- //4. on the results page, select the first search result
- WebElement searchResultLink;
- searchResultLink = driver.findElement(By.xpath("(//a[@testid='bib_link'])[1]"));
- searchResultLink.click();
- Thread.sleep(5000);
- //5. on the result details page, the result title is displayed
- WebElement bookTitleElement;
- bookTitleElement = driver.findElement(By.xpath("//h1[@testid='text_bibtitle']"));
- assertEquals(bookTitleElement.isDisplayed(), true);
- /*
- if (bookTitleElement.isDisplayed() == true){
- System.out.println("the first book name is displayed on the page");
- }
- else{
- System.out.println("the first book name is NOT displayed on the page");
- }
- //6. on the result details page, the result author is displayed
- WebElement bookAuthorElement = driver.findElement(By.xpath("//a[@testid='author_search']"));
- if (bookAuthorElement.isDisplayed() == true){
- System.out.println("the first book author is displayed");
- }
- else{
- System.out.println("the first book author is NOT displayed");
- }
- */
- }
- @Test
- public void test2() {
- //2. open the home page of the site in the browser
- driver.get("http://www.vpl.ca");
- //3. search for a keyword (Java)
- WebElement searchField;
- searchField = driver.findElement(By.xpath("//input[@id='globalQuery']"));
- searchField.click();
- searchField.sendKeys("java");
- WebElement searchButton;
- searchButton = driver.findElement(By.xpath("//input[@class='search_button']"));
- searchButton.click();
- Thread.sleep(5000);
- //4. on the results page, select the first search result
- WebElement searchResultLink;
- searchResultLink = driver.findElement(By.xpath("(//a[@testid='bib_link'])[1]"));
- searchResultLink.click();
- Thread.sleep(5000);
- //5. on the result details page, the result title is displayed
- WebElement bookAuthorElement;
- bookAuthorElement = driver.findElement(By.xpath("//a[@testid='author_search'])[1]"));
- assertEquals(bookAuthorElement.isDisplayed(), true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement