Created
April 12, 2017 15:52
-
-
Save CalamarBicefalo/ef6c7e8eac6537128a14267ba68944c8 to your computer and use it in GitHub Desktop.
Ensures Angular2 is stable before selenium continues. Uses fluentlenium
This file contains hidden or 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
import org.fluentlenium.core.FluentPage | |
import org.fluentlenium.core.domain.FluentList | |
import org.fluentlenium.core.domain.FluentWebElement | |
import org.openqa.selenium.JavascriptExecutor | |
import org.openqa.selenium.WebDriver | |
import java.util.concurrent.TimeUnit | |
open class AbstractPage : FluentPage() { | |
override fun getDriver(): WebDriver { | |
val driver = super.getDriver() | |
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS) | |
return driver | |
} | |
override fun goTo(url: String?) { | |
super.goTo(url) | |
waitForAngular() | |
} | |
protected fun click(elements: FluentList<FluentWebElement>) { | |
elements.click() | |
waitForAngular() | |
} | |
protected fun waitForAngular(componentName: String = "app-root") { | |
val script = """window.getAngularTestability(document.querySelector("$componentName")).whenStable(arguments[0])""" | |
(driver as JavascriptExecutor).executeAsyncScript(script) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment