mardi 3 mai 2016

FluentWait selenium using ThreadLocal

I'm looking for a solution to implement FluentWaits in my java selenium test. The problem is that is use ThreadLocal to declare my drivers as thead-local to run them parallely.

Here is my code :

//My variable declaration
protected ThreadLocal<RemoteWebDriver> threadDriverFirefox = null;

//I create one for my thread in my BeforeTest
threadDriverFirefox = new ThreadLocal<RemoteWebDriver>();
threadDriverFirefox.set(new RemoteWebDriver(new URL(urlnode), DesiredCapabilities.firefox()));

//Add this method to get my driver
 public WebDriver driverFirefox() {
return threadDriverFirefox.get();
}

//And use it like this in my test
driverFirefox().get(weburl);

My problem is with the driverFirefox() I can't find a way to implement it in the FluentWait structure :

Wait waitfluent = new FluentWait(driverFirefox()).withTimeout(30, TimeUnit.SECONDS)
    .pollingEvery(2, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

WebElement testElement = waitfluent.until(new Function() {
    public WebElement apply(WebDriver driverFirefox() ) {
    return WebDriver driverFirefox().findElement(By.id("logEmailField"));
    }
});

But i've a syntax error...

Multiple markers at this line - Syntax error on token ")", delete this token - Syntax error on token(s), misplaced construct(s)

Any idea to fix it ?

Thanks

Aucun commentaire:

Enregistrer un commentaire