-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from healenium/feature/EPMHLM-340
EPMHLM-340
- Loading branch information
Showing
14 changed files
with
117 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/com/epam/healenium/SelfHealingDriverWait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.epam.healenium; | ||
|
||
import org.openqa.selenium.TimeoutException; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.support.ui.Sleeper; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
import java.time.Clock; | ||
import java.time.Duration; | ||
import java.util.function.Function; | ||
|
||
public class SelfHealingDriverWait extends WebDriverWait { | ||
|
||
private final WebDriver webDriver; | ||
|
||
public SelfHealingDriverWait(WebDriver driver, Duration timeout) { | ||
super(driver, timeout); | ||
this.webDriver = driver; | ||
} | ||
|
||
public SelfHealingDriverWait(WebDriver driver, Duration timeout, Duration sleep) { | ||
super(driver, timeout, sleep); | ||
this.webDriver = driver; | ||
} | ||
|
||
public SelfHealingDriverWait(WebDriver driver, Duration timeout, Duration sleep, Clock clock, Sleeper sleeper) { | ||
super(driver, timeout, sleep, clock, sleeper); | ||
this.webDriver = driver; | ||
} | ||
|
||
@Override | ||
public <V> V until(Function<? super WebDriver, V> isTrue) { | ||
if (webDriver instanceof SelfHealingDriver) { | ||
SelfHealingDriver hlmDriver = (SelfHealingDriver) webDriver; | ||
try { | ||
hlmDriver.getCurrentEngine().getSessionContext().setWaitCommand(true); | ||
V until = super.until(isTrue); | ||
hlmDriver.getCurrentEngine().getSessionContext().setWaitCommand(false); | ||
return until; | ||
} catch (TimeoutException timeoutException) { | ||
if (hlmDriver.getCurrentEngine().getSessionContext().isFindElementWaitCommand()) { | ||
hlmDriver.getCurrentEngine().getSessionContext().setWaitCommand(false); | ||
hlmDriver.getCurrentEngine().getSessionContext().setFindElementWaitCommand(false); | ||
V value = isTrue.apply(webDriver); | ||
if (value != null && (Boolean.class != value.getClass() || Boolean.TRUE.equals(value))) { | ||
return value; | ||
} | ||
} | ||
throw timeoutException; | ||
} catch (Exception ex) { | ||
hlmDriver.getCurrentEngine().getSessionContext().setWaitCommand(false); | ||
throw ex; | ||
} | ||
} else { | ||
return super.until(isTrue); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters