I am trying to create a custom Selenium explicit wait with the following code
class TabsOpened implements ExpectedCondition { int expectedTabs; public TabsOpened(int exp) { this.expectedTabs = exp; } @Override public Boolean apply(Object driver) { ArrayList<String> allWindowHandles = new ArrayList<> (((WebDriver)driver).getWindowHandles()); return allWindowHandles.size()== this.expectedTabs; } }
then
wait.until(new TabsOpened(2));
But I am getting these warnings while compilation
Note: Tests.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
Compiling with -Xlint:unchecked flag I get
Tests.java:116: warning: [unchecked] unchecked method invocation: method until in class FluentWait is applied to given types wait.until(new TabsOpened(2)); // Wait 3 seconds or until 2 tabs are opened ^ required: Function<? super T,V> found: TabsOpened where T,V are type-variables: T extends Object declared in class FluentWait V extends Object declared in method <V>until(Function<? super T,V>) Tests.java:116: warning: [unchecked] unchecked conversion wait.until(new TabsOpened(2)); // Wait 3 seconds or until 2 tabs are opened ^ required: Function<? super T,V> found: TabsOpened where T,V are type-variables: T extends Object declared in class FluentWait V extends Object declared in method <V>until(Function<? super T,V>)
Any ideas on how to fix that? I am using Selenium 2.53
Advertisement
Answer
I’m not familiar with this framework but according to the javadoc of the interface you are extending, you should write implements ExpectedCondition<Boolean>
and the parameter of the overridden method should be of type WebDriver
, not Object
.