Skip to content

Instantly share code, notes, and snippets.

@CalamarBicefalo
Created April 12, 2017 15:52
Show Gist options
  • Save CalamarBicefalo/ef6c7e8eac6537128a14267ba68944c8 to your computer and use it in GitHub Desktop.
Save CalamarBicefalo/ef6c7e8eac6537128a14267ba68944c8 to your computer and use it in GitHub Desktop.
Ensures Angular2 is stable before selenium continues. Uses fluentlenium
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