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