|
1 |
| -package com.github.selenium; |
2 |
| - |
3 |
| -import static org.junit.Assert.assertEquals; |
4 |
| -import static org.junit.Assert.assertTrue; |
5 |
| - |
6 |
| -import java.util.concurrent.TimeUnit; |
7 |
| -import java.util.List; |
8 |
| - |
9 |
| -import org.junit.After; |
10 |
| -import org.junit.Before; |
11 |
| -import org.junit.BeforeClass; |
12 |
| -import org.junit.Test; |
13 |
| -import org.openqa.selenium.By; |
14 |
| -import org.openqa.selenium.WebDriver; |
15 |
| -import org.openqa.selenium.WebElement; |
16 |
| -import org.openqa.selenium.chrome.ChromeDriver; |
17 |
| - |
18 |
| -import io.github.bonigarcia.wdm.ChromeDriverManager; |
19 |
| - |
20 |
| -public class ChromeTest { |
21 |
| - |
22 |
| - private static final String BASE_PATH = "https://github.com/hemantsonu20"; |
23 |
| - |
24 |
| - private WebDriver driver; |
25 |
| - |
26 |
| - @BeforeClass |
27 |
| - public static void loadChromeDriver() { |
28 |
| - |
29 |
| - ChromeDriverManager.getInstance().setup(); |
30 |
| - } |
31 |
| - |
32 |
| - @Before |
33 |
| - public void setUpDriver() { |
34 |
| - |
35 |
| - driver = new ChromeDriver(); |
36 |
| - driver.manage().window().maximize(); |
37 |
| - driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); |
38 |
| - } |
39 |
| - |
40 |
| - @After |
41 |
| - public void tearDownDriver() { |
42 |
| - |
43 |
| - driver.quit(); |
44 |
| - } |
45 |
| - |
46 |
| - @Test |
47 |
| - public void openGithubProfile() throws InterruptedException { |
48 |
| - |
49 |
| - // open hemantsonu20's github profile |
50 |
| - driver.get(BASE_PATH); |
51 |
| - |
52 |
| - // assert title of the page with full name |
53 |
| - assertEquals("hemantsonu20 (Pratapi Hemant) · GitHub", driver.getTitle()); |
54 |
| - |
55 |
| - // fetch fullName and username webelement |
56 |
| - WebElement fullName = driver.findElement(By.className("vcard-fullname")); |
57 |
| - WebElement userName = driver.findElement(By.className("vcard-username")); |
58 |
| - |
59 |
| - // assert both elements for visibility |
60 |
| - assertTrue(fullName.isDisplayed()); |
61 |
| - assertTrue(userName.isDisplayed()); |
62 |
| - |
63 |
| - assertEquals("Pratapi Hemant", fullName.getText()); |
64 |
| - assertEquals("hemantsonu20", userName.getText()); |
65 |
| - |
66 |
| - // go to search box, search "hemantsonu20/selenium-sample" and submit |
67 |
| - WebElement searchBox = driver.findElement(By.className("header-search-input")); |
68 |
| - searchBox.sendKeys("hemantsonu20/selenium-sample"); |
69 |
| - searchBox.submit(); |
70 |
| - |
71 |
| - // fetch web-element representing repo-list |
72 |
| - WebElement repoList = driver.findElement(By.className("repo-list")); |
73 |
| - |
74 |
| - // fetch all <a> link tags |
75 |
| - List<WebElement> repoNames = repoList.findElements(By.tagName("a")); |
76 |
| - |
77 |
| - // assert one of the repoNames "href" attribute will contain "/hemantsonu20/selenium-sample" |
78 |
| - boolean found = repoNames.stream().anyMatch(e -> e.getAttribute("href").contains("/hemantsonu20/selenium-sample")); |
79 |
| - assertTrue(found); |
80 |
| - } |
81 |
| -} |
| 1 | +package com.github.selenium; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertTrue; |
| 5 | + |
| 6 | +import java.util.concurrent.TimeUnit; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +import org.junit.After; |
| 10 | +import org.junit.Before; |
| 11 | +import org.junit.BeforeClass; |
| 12 | +import org.junit.Test; |
| 13 | +import org.openqa.selenium.By; |
| 14 | +import org.openqa.selenium.WebDriver; |
| 15 | +import org.openqa.selenium.WebElement; |
| 16 | +import org.openqa.selenium.chrome.ChromeDriver; |
| 17 | + |
| 18 | +import io.github.bonigarcia.wdm.ChromeDriverManager; |
| 19 | + |
| 20 | +public class ChromeTest { |
| 21 | + |
| 22 | + private static final String BASE_PATH = "https://github.com/hemantsonu20"; |
| 23 | + |
| 24 | + private WebDriver driver; |
| 25 | + |
| 26 | + @BeforeClass |
| 27 | + public static void loadChromeDriver() { |
| 28 | + |
| 29 | + ChromeDriverManager.getInstance().setup(); |
| 30 | + } |
| 31 | + |
| 32 | + @Before |
| 33 | + public void setUpDriver() { |
| 34 | + |
| 35 | + driver = new ChromeDriver(); |
| 36 | + driver.manage().window().maximize(); |
| 37 | + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); |
| 38 | + } |
| 39 | + |
| 40 | + @After |
| 41 | + public void tearDownDriver() { |
| 42 | + |
| 43 | + driver.quit(); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void openGithubProfile() { |
| 48 | + |
| 49 | + // open hemantsonu20's github profile |
| 50 | + driver.get(BASE_PATH); |
| 51 | + |
| 52 | + // assert title of the page with full name |
| 53 | + assertEquals("hemantsonu20 (Pratapi Hemant) · GitHub", driver.getTitle()); |
| 54 | + |
| 55 | + // fetch fullName and username webelement |
| 56 | + WebElement fullName = driver.findElement(By.className("vcard-fullname")); |
| 57 | + WebElement userName = driver.findElement(By.className("vcard-username")); |
| 58 | + |
| 59 | + // assert both elements for visibility |
| 60 | + assertTrue(fullName.isDisplayed()); |
| 61 | + assertTrue(userName.isDisplayed()); |
| 62 | + |
| 63 | + assertEquals("Pratapi Hemant", fullName.getText()); |
| 64 | + assertEquals("hemantsonu20", userName.getText()); |
| 65 | + |
| 66 | + // go to search box, search "hemantsonu20/selenium-sample" and submit |
| 67 | + WebElement searchBox = driver.findElement(By.className("header-search-input")); |
| 68 | + searchBox.sendKeys("hemantsonu20/selenium-sample"); |
| 69 | + searchBox.submit(); |
| 70 | + |
| 71 | + // fetch web-element representing repo-list |
| 72 | + WebElement repoList = driver.findElement(By.className("repo-list")); |
| 73 | + |
| 74 | + // fetch all <a> link tags |
| 75 | + List<WebElement> repoNames = repoList.findElements(By.tagName("a")); |
| 76 | + |
| 77 | + // assert one of the repoNames "href" attribute will contain |
| 78 | + // "/hemantsonu20/selenium-sample" |
| 79 | + boolean found = repoNames.stream().anyMatch( |
| 80 | + e -> e.getAttribute("href").contains("/hemantsonu20/selenium-sample")); |
| 81 | + assertTrue(found); |
| 82 | + } |
| 83 | +} |
0 commit comments