New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use SelenideElement if it was declared before setWebDriver() method #873
Comments
From what I understand, by using $() you setting up a default driver and $ uses it to declare SelenideElement, so if you're setting driver manually after $ then Selenide closes previous one and that is why you get the error. SelenideElement a=$("abc"); // default driver (created for you automatically)
WebDriverRunner.setWebDriver(new ChromeDriver()); // your driver, default driver being closed
open("http://google.com"); // using your driver
a.shouldNot(exist); // as this is proxy it remembers default driver from line 1 I think this is not an bug, you should set driver before using it. if you need to declare element before then declare selector only as String and after setting up the driver use $() |
$() 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 ***@***.***) wrote:
From what I understand, by using $() you setting up a default driver and $
uses it to declare SelenideElement, so if you're setting driver manually
after $ then Selenide closes previous one and that is why you get the error.
SelenideElement a=$("abc"); // default driver (created for you automatically)WebDriverRunner.setWebDriver(new ChromeDriver()); // your driver, default driver being closed
open("http://google.com"); // using your driver
a.shouldNot(exist); // as this is proxy it remembers default driver from line 1
I think this is not an bug, you should set driver before using it. if you
need to declare element before then declare selector only as String and
after setting up the driver use $()
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#873 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGQ4YI_i4aYdKRKwlwNdTCwLL41QblZZks5u2PACgaJpZM4ZCdXD>
.
|
@jkromski that would have been true if it didn't work without using setWebDriver() method, letting Selenide setup driver, but it's not the case. The issue is only happening when setWebDriver method is used. See my example above without usage of setWebDriver, where element is declared as a field - this still works. |
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 ***@***.***) wrote:
@jkromski <https://github.com/jkromski> that would have been true if it
didn't work without using setWebDriver() method, letting Selenide setup
driver, but it's not the case. The issue is only happening when
setWebDriver method is used. See my example above without usage of
setWebDriver, where element is declared as a field - this still works.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#873 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGQ4YGlQdWzwKCbtrMcn9vkhsFYxj1qVks5u2PRkgaJpZM4ZCdXD>
.
|
@pavelpp @jkromski @vinogradoff No, it's not a bug. It was a decision made in Selenide 5.0. See https://selenide.org/2018/10/10/selenide-5.0.0/:
It may see a bit unexpected, but I believe it will cause a better design of your tests. For me, it's really a strange decision to declare |
It is indeed unexpected as it used to work before and not anymore. Secondly, if it's not supposed to work like this then the behaviour is not consistent when setWebDriver method is not used. How do you explain this? @asolntsev Make it work the same way in both cases, otherwise it just does not make any sense. |
@pavelpp Well, I agree, Selenide should throw IllegalStateException even if P.S. But it will not solve your problem. :) |
@asolntsev it's fine as long as the behaviour is consistent |
Agree, lets improve what we are telling the user under this circumstance, but I think its a very uncommon to write test code like this |
I still see it as a bug. I will propose a fix later this week.
|
@vinogradoff before you start fixing something, could you explain why you think it's a bug? It was an intentional change. |
Sure. This fails.
This works
WebDriver is changed before open - perfectly fine. There is no reason to connect elements definition with any WebDriver instance, so it may happen in any place. And as far as I remember it is not even connected, but doesn't work as a side effect due to some other minor issue in setWebDriver calls. |
And where is the real problem? |
I still insist that the line doesn't search and doesn't find. It declares location algorithm. Declaration can be placed anywhere. This example is of course just a short snippet to reproduce. |
@vinogradoff Who said that? Why? I never said it. Anyway, my question is still in the air:
|
There is a better solution - to make a code change and let the both snippets to have the same result. |
You are not answering my questions. :( |
If you insist.
I was never saying it was you. I don't know who says it except me. Why - because it work this way.
The different behaviour of the two snippets is illogical. It is a real problem with quality, yes. That you have workaround doesn't make the problem less real.
We cannot find element before opening the browser, for sure. But even if you put "find" and "declare" to be equal, and even if I would agree that it is better to declare element after Then please answer my question in return: Why you resist a change that would make these both pieces of code work consistently? What are the reasons not to do it? (of course you must not do it yourself). |
@vinogradoff of course, inconsistency is bad. As I said in a comment above, Selenide should throw If you want to declare elements, just declare |
Where I called
Why? Why you don't want me to declare SelenideElement as I always do the last years? |
just beware, that if you throw IllegalStateException every time, $() is used, bevor open() is called - it will break plenty of tests, probably my tests too. For what reason? |
This is indeed a bug. It prevents me from upgrading to Selenide 5+ Well, @asolntsev said
I have collection of elements for each page on top of my java class (like 800+ of them), they're all organized and commented. They are being used in MULTIPLE tests below. It is way easier and makes more sense to create an array of elements of the page first, then use them where needed in tests. It shouldn't have anything to do with browser setup, it also has nothing to do with $ and $$ opening browsers. It's just a collection of elements and it shouldn't affect setup and tests execution. |
@BlackwellQA Well, it was not a bug, it was an intentional change because I believed it will cause better design of tests. :) But still, don't you think that having 800+ fields in a single class is a bad design? I mean, BAD design? It breaks all principles of software disciplines like SRP, KISS etc. A big class with many responsibilities is a well-known antipattern in programming (not only in test automation). Don't you think that splitting the huge class to many small page objects would cause a much better design? |
@asolntsev Thank you for your reply Andrei :) I managed to get everything working by adding By and $() everywhere, which is not bad but more things to type when with just elements collection looks a bit cleaner :) The error was very confusing and I tried to rewrite my browser factory and everything, but issue was that elements were before page opening separated from the tests. Design wise I understand where you're coming from, but in my specific case I do DNA traits and indexes automation and they all have to be together in one class unfortunately. |
I preapare instances of page objects before running parameterised tests via Juni5 ArgumentsProvider. Page objects already includes fields and actions with $. Next browser is selected before each test and if browser changes from default, it produses that problem.. Actualy, it wasn't a big problem. I've just moved invocation of page object into test. |
Hi, I have the same problem. |
In @scope the interfaces was added proxyMode = ScopedProxyMode.TARGET_CLASS. It solved my problem. EXAMPLE: Target (TYPE) |
I have the same problem: @before(order = 1) - I use properies file (only string like user name, pass etc) java.lang.IllegalStateException: Webdriver has been closed. You need to call open(url) to open a browser again. @before(order = 1)
} After(in different class) I want to use: public class LoginPage {
And I am getting :
|
@pavelpp @jkromski @BlackwellQA @ivalitov @Skaramus1990 @MichalUrbaniakQA Congratulations, this change was implemented in Selenide 5.4.1. |
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
Tell us about your environment
Code To Reproduce Issue [ Good To Have ]
Easily reproducible with:
And this way it works
Also this works
And this does not
The text was updated successfully, but these errors were encountered: