forked from JeeKayPee/CSE-Code-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseTest3.java
More file actions
55 lines (45 loc) · 1.66 KB
/
Copy pathBaseTest3.java
File metadata and controls
55 lines (45 loc) · 1.66 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
package common;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class BaseTest3 {
private WebDriver driver = null;
private WebDriverWait wait = null;
@BeforeEach
public void login() throws Exception {
// Create Driver
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
setDriver(Configuration.createChromeDriver(options));
wait = new WebDriverWait(getDriver(), 60);
// Login
getDriver().get(Configuration.ADMIN_URL);
WebElement userTextBox = wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("log")));
userTextBox.sendKeys(Configuration.USER_NAME);
WebElement pwdTextBox = getDriver().findElement(By.name("pwd"));
pwdTextBox.sendKeys(Configuration.PASSWORD);
pwdTextBox.submit();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("wpadminbar")));
}
@AfterEach
public void logout() throws Exception {
WebElement logOut = getDriver().findElement(By.xpath("//*[text()='Log Out']"));
getDriver().get(logOut.getAttribute("href"));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(text(),'logged out')]")));
getDriver().quit();
}
protected WebDriver getDriver(){
return this.driver;
}
private void setDriver(WebDriver driver) {
this.driver = driver;
}
protected WebDriverWait getWaiter(){
return this.wait;
}
}