serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
723 stars 518 forks source link

old fluentlenium dependency incompatible with selenium dependency, causes java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.FluentWait.until(Lcom/google/common/base/Predicate;)V #2213

Closed benjamin-sailer closed 2 years ago

benjamin-sailer commented 4 years ago

Using net.serenity-bdd:serenity-core:jar:2.2.13:compile, I encountered a NoSuchMethodError:

java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.FluentWait.until(Lcom/google/common/base/Predicate;)V

    at org.fluentlenium.core.wait.FluentWait.until(FluentWait.java:98)
    at org.fluentlenium.core.wait.FluentWaitMatcher.until(FluentWaitMatcher.java:67)
    at org.fluentlenium.core.wait.FluentWaitMatcher.areDisplayed(FluentWaitMatcher.java:216)
    at <MyClass.MyMethod(MyClass.java:myLine)>

The last line of our code is MyClass.MyMethod(MyClass.java:myLine:

await().atMost(waitDurationInSeconds, TimeUnit.SECONDS).until(".ui-autocomplete-item").areDisplayed()

Digging a bit into this, i found an (non-)issue of https://github.com/SeleniumHQ/selenium/issues/3606, which basically turned out to be a version incompatibility, which I would pin down to serenity-core's fluentlenium-dependency, which is quite old - around April 16, the newest version is 4.3.1. From mvn dependency:tree, I get:

<my-group-id:my-artifact:jar:myversion:compile>
+- net.serenity-bdd:serenity-core:jar:2.2.13:compile
.  ....
|  +- org.fluentlenium:fluentlenium-core:jar:0.10.2:compile
.  ....

If I open the class org.fluentlenium.core.wait.FluenWait of this dependency in my IDE, it already detects compile errors like:

 96    public FluentWait until(com.google.common.base.Predicate<Fluent> isTrue) {
 97        updateWaitWithDefaultExceptions();
 98        wait.until(isTrue);
 99        return this;
100    }

(line 98: Required Type: Function; Provided: Predicate)

Unfortunately fluentlenium did a major rework of their API even between 0.x and 1.0, so adapting to a newer version was out of scope for me for this bug report.

Please consider upgrading the fluentlenium dependency.

All the best Benajmin

benjamin-sailer commented 4 years ago

Just for the record: Moving to Java 11 fixed that issue partly. As a workaround I copied the FluentWait-class into my project (using the same package) and modified two the two until methods to a) accept java.util.function.Function and

import java.util.function.Function;
...
    @Override
    public <T> T until(Function<? super Fluent, T> isTrue) {
        updateWaitWithDefaultExceptions();
        return wait.until(isTrue);
    }

b) provide a function calling isTrue.accept to wait.until:

    public FluentWait until(com.google.common.base.Predicate<Fluent> isTrue) {
        updateWaitWithDefaultExceptions();
        wait.until(f -> isTrue.apply(f));
        return this;
    }

Seems (probably more than) a bit hacky as this relies on the classloader feeding my own version of org.fluentlenium.core.wait.FluentWait instead of the one provided by the fluentlenium dependency. Works for me but anyway a dependency upgrade may be worth a try in serenity-bdd core.

wakaleo commented 4 years ago

We will probably deprecate FluentLenium integration in future versions as the $() operator in Serenity does much the same thing.

benjamin-sailer commented 4 years ago

Which would mean basically dropping the ThucydidesFluentAdapter and the PageObject.fluent() method (resp. marking them @deprecated in the first step)? Looking forward to seeing the new version and getting an idea how much this would change (I assume in our case it wouldn't be a long way to go).