News for hackers. Stuff that matters.
Re:How to make Selenium tests reliable, scalable, and mainta... by paulddraper on Tuesday July 21, 2015 @06:24PM (#9926298)
The most annoying thing I found with Selenium was that it wouldn't wait for the browser to respond to click events and rerender.

The approach in the blog post (and I think elsewhere ... not sure) is to poll the DOM with a timeout.

Is there a better solution to be add with something like `executeScript`? You could run `requestAnimationFrame`, and then poll for an indicator that the click, etc. handler has indeed finished. That way if it fails, you know about it pretty soon, without the need for long timeouts. This is all just a guess though.

Re:How to make Selenium tests reliable, scalable, and mainta... by crdoconnor on Wednesday July 22, 2015 @04:54AM (#9928417)
>Is there a better solution

Yes. And it's pretty simple:

    WebDriver driver = new FirefoxDriver();
    driver.get("http://somedomain/url_that_delays_loading");
    WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));
From : http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp
Re:How to make Selenium tests reliable, scalable, and mainta... by drothlis on Wednesday July 22, 2015 @11:17AM (#9930098)
I'm not sure this satisfies your parent poster's requirement of: "if it fails, you know about it pretty soon, without the need for long timeouts."
Re:How to make Selenium tests reliable, scalable, and mainta... by crdoconnor on Wednesday July 22, 2015 @11:27PM (#9933810)
Well, you need to have a timeout.

You can make the timeout shorter when running the test on a dev environment, though, so you get quicker feedback about errors.

Re:How to make Selenium tests reliable, scalable, and mainta... by pmontra on Wednesday July 22, 2015 @02:40AM (#9928059)
Ruby's Capybara encapsulates Selenium and waits until elements appear on the page (the default timeout is 2 seconds). So you can write simple sequential code like

    click_link('bar')
    expect(page).to have_content('baz')
and it will work even if the baz element is injected into the page by an Ajax request to the server triggered by clicking on bar. I've been using it for many years but I didn't check how they implement it. Maybe a callback from a MutationObserver? https://developer.mozilla.org/en-US/docs/Web/API/MutationObs...

Documentation at https://github.com/jnicklas/capybara#asynchronous-javascript...

Re:How to make Selenium tests reliable, scalable, and mainta... by drothlis on Wednesday July 22, 2015 @11:34AM (#9930211)
According to that documentation you linked, it just polls until `default_max_wait_time` (which defaults to 2 seconds).
Re:How to make Selenium tests reliable, scalable, and mainta... by glenk on Wednesday July 22, 2015 @01:14AM (#9927856)
I have had some good results using the F# canopy library(http://lefthandedgoat.github.io/canopy/) for working with selenium. It handles (most) all the waits for you so you don't have to scatter a bunch of sleeps in your tests and is pretty easy to work with.
Re:How to make Selenium tests reliable, scalable, and mainta... by jakejake on Wednesday July 22, 2015 @12:26AM (#9927730)
There's some utility methods like FluentWait, but ultimately they're just convenience wrappers for polling the DOM and waiting.