long time lurker here, now it's time for my first real post. I am currently developing a cross browser test for our application with Selenium in .NET.
Following http://www.guru99.com/cross-browser-testing-using-selenium.html, I implemented this:
[SetUpFixture]
public class TestSetup()
{
public static IWebDriver driver;
...
[OneTimeSetUp]
public void GlobalSetup()
{
if(browserToTest.Equals("Firefox"))
{
driver = new FirefoxDriver();
}
else if(browserToTest.Equals("Chrome"))
{
driver = new ChromeDriver();
}
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10.00);
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(10.00);
// navigate to url, login, etc. pp
}
}
In the "Firefox" case, everything works great. The "Chrome" case - in contrary to the tutorial - gives me this error:
OneTimeSetUp: System.NotImplementedException : Driver instance must comply with the W3C specification to support getting timeout values.
Im using:
Can I set ImplicitWait and PageLoad for chrome, or is this only implemented for firefox?
i used this code which worked for me in both chrome and firefox. PageObject is my class and waitPageToLoad is my method.
public class PageObject {
protected Logger log = LogManager.getLogger(this.getClass().getName());
protected WebDriver driver;
protected WebDriverWait wait;
public WebDriver getDriver() {
log.debug("obtaining the driver object for current thread");
return driver;
}
public WebDriverWait getWait() {
log.debug("obtaining the wait object for current thread");
return wait;
}
public void initialise(Object obj) {
PageFactory.initElements(getDriver(), obj);
}
public PageObject waitPageToLoad() {
domLoaded();
jqueryLoaded();
return this;
}
public void domLoaded() {
log.debug("checking that the DOM is loaded");
final JavascriptExecutor js = (JavascriptExecutor) getDriver();
Boolean domReady = js.executeScript("return document.readyState").equals("complete");
if (!domReady) {
getWait().until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return (js.executeScript("return document.readyState").equals("complete"));
}
});
}
}
private void jqueryLoaded() {
log.debug("checking that any JQuery operations complete");
final JavascriptExecutor js = (JavascriptExecutor) getDriver();
if ((Boolean) js.executeScript("return typeof jQuery != 'undefined'")) {
boolean jqueryReady = (Boolean) js.executeScript("return jQuery.active==0");
if (!jqueryReady) {
getWait().until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return (Boolean) js.executeScript("return window.jQuery.active === 0");
}
});
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With