forked from TalhaBinAshraf1/SeleniumTestingInternetHerokuApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicContent.java
More file actions
63 lines (52 loc) · 2.07 KB
/
Copy pathDynamicContent.java
File metadata and controls
63 lines (52 loc) · 2.07 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
package allTests;
import org.testng.annotations.Test;
import utility.BaseTest;
import utility.FrameworkConstants;
import java.time.Duration;
import java.util.function.Function;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.FluentWait;
public class DynamicContent extends BaseTest{
@Test
public void test() throws InterruptedException {
System.setProperty(FrameworkConstants.CHROME_DRIVER_KEY,FrameworkConstants.CHROME_DRIVER_PATH);
WebDriver driver = new ChromeDriver();
driver.findElement(By.xpath("//a[contains(text(),'Dynamic Loading')]")).click();
hiddenElementCheck(driver);
renderedElementCheck(driver);
driver.quit();
}
private void hiddenElementCheck(WebDriver driver) {
driver.findElement(By.partialLinkText("Example 1")).click();
driver.findElement(By.xpath("//button[contains(text(),'Start')]")).click();
waitForloadingToComplete(driver);
System.out.println(driver.findElement(By.cssSelector("div#finish>h4")).getText());
}
private void renderedElementCheck(WebDriver driver) {
driver.findElement(By.partialLinkText("Example 2")).click();
driver.findElement(By.xpath("//button[contains(text(),'Start')]")).click();
waitForloadingToComplete(driver);
System.out.println(driver.findElement(By.cssSelector("div#finish>h4")).getText());
}
private void waitForloadingToComplete(WebDriver driver) {
System.out.println("Loading check");
FluentWait<WebDriver> fw = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofMillis(500))
.ignoring(Exception.class);
Function<WebDriver, Boolean> func = new Function<WebDriver, Boolean>() {
public Boolean apply(WebDriver driver) {
WebElement loadingIcon = driver.findElement(By.cssSelector("div#loading"));
String displayValue = loadingIcon.getCssValue("display");
if(displayValue.equals("none")) {
return true;
}
return false;
}
};
fw.until(func);
}
}