-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSeleniumBase.java
More file actions
136 lines (106 loc) · 3.28 KB
/
Copy pathSeleniumBase.java
File metadata and controls
136 lines (106 loc) · 3.28 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package base;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.Alert;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class SeleniumBase {
protected RemoteWebDriver driver;
private WebDriverWait wait;
private long timeOut = 30;
public void type(WebElement ele, String text) {
wait = new WebDriverWait(driver, timeOut);
wait.until(ExpectedConditions.visibilityOf(ele));
ele.sendKeys(text);
log("The value "+text+" is typed");
}
public void clearAndType(WebElement ele, String text) {
ele.clear();
ele.sendKeys(text);
log("The value is clear and then "+text+" is typed");
}
public boolean isDisplayed(WebElement ele) {
return ele.isDisplayed();
}
public boolean isReadOnly(WebElement ele) {
String isRead = ele.getAttribute("readonly");
if(isRead.equals("true")) {
return true;
}else return false;
}
public void click(WebElement ele) {
wait = new WebDriverWait(driver, 20);
WebElement readyEle = wait.until(ExpectedConditions.elementToBeClickable(ele));
readyEle.click();
log("The ele is clicked");
}
public String getElementColor(WebElement ele) {
String cssValue = ele.getCssValue("background-color");
log("background-color is "+cssValue);
return cssValue;
}
// TODO: Enhance it later
public void selectText(WebElement ele, String visibleText) {
Select select = new Select(ele);
select.selectByVisibleText(visibleText);
WebElement selectedOption = select.getFirstSelectedOption();
if(selectedOption.getText().equals(visibleText)) {
log("is Selcted: "+visibleText);
}else {
log("Option is not there: "+visibleText);
}
}
// TODO: you have to complete
public void selectIndex(WebElement el,int inex) {
}
// TODO: you have to complete
public void selectValue(WebElement el,String value) {
}
public void acceptAlert() {
Alert alert = driver.switchTo().alert();
log("Alert text is: "+alert.getText());
alert.accept();
}
public void dismissAlert() {
Alert alert = driver.switchTo().alert();
log("Alert text is: "+alert.getText());
alert.dismiss();
}
public void typeInAlert(String text) {
Alert alert = driver.switchTo().alert();
log("Alert text is: "+alert.getText());
alert.sendKeys(text);
}
public void switchToFrame(int i) {
driver.switchTo().frame(i);
log("Switched to the "+i+" th frmae");
}
public void switchToFrame(WebElement ele) {
driver.switchTo().frame(ele);
log("Switched to the frmae");
}
public void switchToFrame(String nameOrId) {
driver.switchTo().frame(nameOrId);
log("Switched to the frmae");
}
public boolean isElementDisplayed(WebElement ele) {
log(ele.isDisplayed());
return ele.isDisplayed();
}
public void switchToWindow(int i) {
Set<String> windowHandles = driver.getWindowHandles();
List<String> list = new ArrayList<String>(windowHandles);
int size = list.size();
System.out.println("No.of windows: "+size);
driver.switchTo().window(list.get(i));
log("Switched to the window");
}
public void log(Object message) {
System.out.println(message);
}
}