selenide: Can't use SelenideElement if it was declared before setWebDriver() method
The problem
As per issue title, declaring a SelenideElement before calling WebDriverRunner.setWebDriver(driver) method leads to an IllegalStateException whenever user tries to interact with the element.
Details
If we do not use setWebDriver method, then everything works regardless of where you declare SelenideElement. It can be a test class field for instance and still works. Exception stacktrace
java.lang.IllegalStateException: Webdriver has been closed. You need to call open(url) to open a browser again.
at com.codeborne.selenide.drivercommands.LazyDriver.getWebDriver(LazyDriver.java:65)
at com.codeborne.selenide.impl.ElementFinder.getSearchContext(ElementFinder.java:86)
at com.codeborne.selenide.impl.ElementFinder.getWebElement(ElementFinder.java:74)
at com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:47)
at com.codeborne.selenide.commands.Should.should(Should.java:35)
at com.codeborne.selenide.commands.Should.execute(Should.java:29)
at com.codeborne.selenide.commands.Should.execute(Should.java:12)
at com.codeborne.selenide.commands.Commands.execute(Commands.java:144)
at com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:99)
at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65)
at com.sun.proxy.$Proxy5.shouldBe(Unknown Source)
Tell us about your environment
- Selenide Version: 5.0.1
- Chrome\Firefox\IE Version: irrelevant
- Browser Driver Version: irrelevant
- Selenium Version: 3.x
- OS Version: irrelevant
Code To Reproduce Issue [ Good To Have ]
Easily reproducible with:
SelenideElement a=$("abc");
WebDriverRunner.setWebDriver(new ChromeDriver());
open("http://google.com");
a.shouldNot(exist);
And this way it works
WebDriverRunner.setWebDriver(new ChromeDriver());
SelenideElement a=$("abc");
open("http://google.com");
a.shouldNot(exist);
Also this works
public class SimpleTest {
public SelenideElement search = $(By.name("q"));
@Test
public void testSimple() {
open("https://www.google.com");
search.shouldBe(Condition.visible);
}
}
And this does not
public class SimpleTest {
public SelenideElement search = $(By.name("q"));
@Test
public void testSimple() {
WebDriverRunner.setWebDriver(new ChromeDriver(new ChromeOptions()));
open("https://www.google.com");
search.shouldBe(Condition.visible);
}
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 29 (23 by maintainers)
I still see it as a bug. I will propose a fix later this week.
Actually, I’ve looked into code and it looks like bug. I hope to fix it until Sunday.
Viele Grüße
Alexei Vinogradov
On 6. December 2018 at 11:41:40, pavelpp (notifications@github.com) wrote:
$() is not supposed to set up any particular driver, it just making use of a drivers configured at other places.
So I guess it is a bug)
Viele Grüße
Alexei Vinogradov
On 6. December 2018 at 11:22:58, Jacek (notifications@github.com) wrote: