-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestWebdriverWait.java
More file actions
109 lines (87 loc) · 2.93 KB
/
Copy pathTestWebdriverWait.java
File metadata and controls
109 lines (87 loc) · 2.93 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
package testcase;
import helper.FluentWaitHelper;
import helper.StartWebDriver;
import helper.WindowHelper;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.ElementNotVisibleException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
import com.google.common.base.Function;
/**
* @author - rahul.rathore
* @date - 16-Nov-2014
* @project - Webdriver
* @package - testcase
* @file name - TestWebdriverWait.java
*/
public class TestWebdriverWait extends StartWebDriver {
@Test
public void testWait() {
WindowHelper.navigateToPage("http://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock");
driver.switchTo().frame((driver.findElement(By.id("iframeResult"))));
WebDriverWait wait = new WebDriverWait(driver, 100);
wait.pollingEvery(1, TimeUnit.SECONDS);
Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver arg0) {
if(arg0.findElement(By.id("txt")).getText().contains("40")){
System.out.println("Counter : " + arg0.findElement(By.id("txt")).getText());
return true;
}
else {
System.out.println("Number : " + arg0.findElement(By.id("txt")).getText());
return false;
}
}
};
wait.until(function);
System.out.println("40 Number Found");
}
@Test
public void TestluentWaitHelper() {
List<Class> exception = new LinkedList<Class>();
exception.add(NoSuchElementException.class);
exception.add(ElementNotVisibleException.class);
FluentWaitHelper helper = new FluentWaitHelper();
helper.setDriver(driver)
.setPollingInterval(500)
.setTimeOut(60)
.setIgnoreExceptionList(exception)
.build();
helper.waitFor(waitForElement(By.id("123")));
helper.waitFor(ExpectedConditions.alertIsPresent());
}
public static Function<WebDriver, WebElement> waitForElement(final By locator) {
Function<WebDriver, WebElement> waitFunction = new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver t) {
return t.findElement(locator);
}
};
return waitFunction;
}
private Function<WebDriver, Boolean> waitForTimer(final By aLocator,final String aValue){
Function<WebDriver, Boolean> waitFunction = new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
if(getTheTextOfElement(aLocator, driver).equalsIgnoreCase(aValue))
return true;
else{
System.out.println("Value : " + getTheTextOfElement(aLocator, driver));
return false;
}
}
};
return waitFunction;
}
private String getTheTextOfElement(final By aLocator, WebDriver driver) {
return driver.findElement(aLocator).getText();
}
}