forked from TalhaBinAshraf1/SeleniumTestingInternetHerokuApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomWait.java
More file actions
178 lines (149 loc) · 5.23 KB
/
Copy pathCustomWait.java
File metadata and controls
178 lines (149 loc) · 5.23 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package allTests;
import org.openqa.selenium.By;
import org.openqa.selenium.ElementNotInteractableException;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
//import com.relevantcodes.extentreports.LogStatus;
public class CustomWait extends BaseTest{
public void forElementVisibility(WebElement webelement) {
wait = new WebDriverWait(driver, FrameworkConstants.OBJECT_LOAD_TIME_OUT);
wait.until(ExpectedConditions.visibilityOf(webelement));
}
public void forElementClickablity(WebElement webelement) {
System.out.println("To check element clickability");
wait = new WebDriverWait(driver, FrameworkConstants.OBJECT_LOAD_TIME_OUT);
wait.until(ExpectedConditions.elementToBeClickable(webelement));
}
public void forElementVisibility(WebElement webelement, int customTimeout) {
wait = new WebDriverWait(driver, customTimeout);
wait.until(ExpectedConditions.visibilityOf(webelement));
}
public void forElementInVisibility(By locator) throws InterruptedException {
wait = new WebDriverWait(driver, FrameworkConstants.OBJECT_LOAD_TIME_OUT);
wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));
}
public void forElementInVisibility(By locator, int customTimeout) throws InterruptedException {
wait = new WebDriverWait(driver, customTimeout);
wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));
}
public void forAlertToBePresent() {
wait = new WebDriverWait(driver, FrameworkConstants.OBJECT_LOAD_TIME_OUT);
wait.until(ExpectedConditions.alertIsPresent());
}
public void forAlertToBePresent(int customTimeout) {
wait = new WebDriverWait(driver, customTimeout);
wait.until(ExpectedConditions.alertIsPresent());
}
public void forPageTitle(String pagetitle) {
wait = new WebDriverWait(driver, FrameworkConstants.OBJECT_LOAD_TIME_OUT);
wait.until(ExpectedConditions.titleIs(pagetitle));
}
public void forPageTitle(String pagetitle, int customTimeout) {
wait = new WebDriverWait(driver, customTimeout);
wait.until(ExpectedConditions.titleIs(pagetitle));
}
public void forPageToLoad(WebElement webelement) {
wait = new WebDriverWait(driver, FrameworkConstants.PAGE_LOAD_TIME_OUT);
wait.until(ExpectedConditions.visibilityOf(webelement));
// test.log(LogStatus.INFO, "Webpage loaded within timeout period "+FrameworkConstants.PAGE_LOAD_TIME_OUT+" secs");
}
public void forPageToLoad(WebElement webelement, int customTimeout) {
wait = new WebDriverWait(driver, customTimeout);
wait.until(ExpectedConditions.visibilityOf(webelement));
}
public void forPageToLoad(String pageTitle) {
wait = new WebDriverWait(driver, FrameworkConstants.PAGE_LOAD_TIME_OUT);
wait.until(ExpectedConditions.titleIs(pageTitle));
}
public void forPageToLoad(String pageTitle, int customTimeout) {
forPageTitle(pageTitle,customTimeout);
}
public void forTextToBePresent(String text){
text.trim();
int count = 0;
boolean flag = false;
do {
if(driver.getPageSource().contains(text)) {
flag = true;
break;
} else {
count++;
forXseconds(1);
}
} while (count < FrameworkConstants.OBJECT_LOAD_TIME_OUT);
if(!flag) {
throw new TimeoutException("Search text not found on the webpage after timeout period of "+FrameworkConstants.OBJECT_LOAD_TIME_OUT+" secs");
}
}
public void forTextToBePresent(String text, int customTimeout){
text.trim();
int count = 0;
boolean flag = false;
do {
if(driver.getPageSource().contains(text)) {
flag = true;
// test.log(LogStatus.INFO, "Search text found on the webpage");
break;
} else {
count++;
forXseconds(1);
}
} while (count < customTimeout);
if(!flag) {
throw new TimeoutException("Search text not found on the webpage after timeout period of "+customTimeout+" secs");
}
}
public void forElementToBeEnabled(WebElement webelement) {
int count = 0;
boolean flag = false;
do {
if(webelement.isEnabled()) {
flag = true;
break;
} else {
count++;
forXseconds(1);
}
} while (count < FrameworkConstants.OBJECT_LOAD_TIME_OUT);
if(!flag) {
throw new ElementNotInteractableException("Element disabled");
}
}
public void forElementToBeEnabled(WebElement webelement, int customTimeout) {
int count = 0;
boolean flag = false;
do {
if(webelement.isEnabled()) {
flag = true;
break;
} else {
count++;
forXseconds(1);
}
} while (count < customTimeout);
if(!flag) {
throw new ElementNotInteractableException("Element disabled");
}
}
public void forElementToBeVisibleAndEnabled(WebElement webelement) {
forElementVisibility(webelement);
forElementToBeEnabled(webelement);
}
public void forElementToBeVisibleAndEnabled(WebElement webelement, int customTimeout) {
forElementVisibility(webelement,customTimeout);
forElementToBeEnabled(webelement,customTimeout);
}
public void forXseconds(int seconds) {
seconds = seconds * 1000;
try {
Thread.sleep(seconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}