-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(selenium): add AssertUrl action
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
actor/selenium/src/main/java/org/getopentest/selenium/AssertUrl.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,40 @@ | ||
package org.getopentest.selenium; | ||
|
||
import java.util.regex.Pattern; | ||
import org.getopentest.selenium.core.CustomConditions; | ||
import org.getopentest.selenium.core.SeleniumTestAction; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
public class AssertUrl extends SeleniumTestAction { | ||
|
||
@Override | ||
public void run() { | ||
|
||
super.run(); | ||
|
||
String urlIs = this.readStringArgument("urlIs", null); | ||
String urlContains = this.readStringArgument("urlContains", null); | ||
Pattern urlMatches = this.readRegexArgument("urlMatches", null); | ||
|
||
this.waitForAsyncCallsToFinish(); | ||
|
||
Pattern regexPattern = null; | ||
|
||
if (urlIs != null) { | ||
regexPattern = Pattern.compile("^" + Pattern.quote(urlIs) + "$"); | ||
} else if (urlContains != null) { | ||
regexPattern = Pattern.compile("^.*" + Pattern.quote(urlContains) + ".*$"); | ||
} else if (urlMatches != null) { | ||
regexPattern = urlMatches; | ||
} | ||
|
||
try { | ||
WebDriverWait wait = new WebDriverWait(this.driver, this.getExplicitWaitSec()); | ||
wait.until(CustomConditions.urlToMatch(regexPattern)); | ||
} catch (Exception ex) { | ||
throw new RuntimeException(String.format( | ||
"Failed to validate the current page URL. At the time of this error, the URL was %s", | ||
driver.getCurrentUrl()), ex); | ||
} | ||
} | ||
} |
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