Selenide: Add current URL on the error message

Created on 2 Oct 2019  Â·  7Comments  Â·  Source: selenide/selenide

The problem

The error message on a test failure doesn't display the URL where we are getting the error.

Details

The following message is helpful. It would be great to add the URL as well.

com.codeborne.selenide.ex.ElementNotFound: Element not found {#dashboardButton}
Expected: visible or transparent: visible or have css value opacity=0
Screenshot: file:/C:/_work/app/build/reports/tests/1570048960084.0.png
Page source: file:/C:/_work/app/build/reports/tests/1570048960084.0.html
Timeout: 4 s.
Caused by: NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#dashboardButton"}

    at com.codeborne.selenide.impl.WebElementSource.createElementNotFoundError(WebElementSource.java:37)
    at com.codeborne.selenide.impl.ElementFinder.createElementNotFoundError(ElementFinder.java:100)
    at com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:65)

Possible Solution:

We may need to update com.codeborne.selenide.ex.UIAssertionError#uiDetails() and com.codeborne.selenide.ex.ErrorMessages to pull the current url from driver object:

driver.getWebDriver().getCurrentUrl();

feature help wanted not sure

All 7 comments

@gtiwari333 Why not, good idea. Let's do it!

Should be done carefully. Url can be quite large and in this case it will make error message hideous

Good point. Probably some substring could help?

Ok lets think.

Scenario:
As software test automation I want to find root cause of failed test quicker.

Given I see current app url in stacktrace
Then I open url?
Or I attach to bug report?

I don't know for what we need url in stacktrace.

Pros
1) Common reason - make failure message more rich.
2) Non technical team members can easily open app and compare sceen from error and page itself (and don't open test code lol)
3) Can quickly open application from stacktrace I look at what is wrong.

Cons
1) For modern SPA application it is useless. They often use one route for serving bunch of pages.
2) For enterprise apps url can be very large enormous and will make error hideous(or if we trim url we won't have any cons I mentioned above)
3) Often you can just open url and server returns corresponding page... So for what we need such url?
4) Often app has authentication, so we cant just open url from error and see page. We have to find userpassword, log in to app and then open corresponding page from error. A lot of steps, isnt it?

From my point of view we have to address why we add url to make decision how to trim it.
We can

  • trim domain name at all - it is ok, we know relative url and can understand what the page is
  • trim all but not domain - we will know where we ran tests e.g. which test env
  • trim query params - for some cases it will make url less, but useless - we can't open url ¯_(ツ)_/¯

@gtiwari333 can you describe for what you need url in error message?

@gtiwari333 ^^^ ping ^^^

The main advantage of knowing the URL is to save a bunch of click and navigation through the page to get into the problematic page.

I agree on the Scenario and all Pros that BorisOsipov posted. I have following feedback on the Cons.

For modern SPA application it is useless. They often use one route for serving bunch of pages.
-> Agreed. But knowing the url takes us to the problematic page faster.

For enterprise apps url can be very large enormous and will make error hideous(or if we trim url we won't have any cons I mentioned above)
-> Can we make it a configuration option to decide if we should print the URL or not?

Often you can just open url and server returns corresponding page... So for what we need such url?
-> I didn't get this. What do you mean by "you can just open url" ?

Often app has authentication, so we cant just open url from error and see page. We have to find userpassword, log in to app and then open corresponding page from error. A lot of steps, isnt it?
-> Assuming you are already logged in. You can simply open the URL and get into the desired page.

Probably it's a good candidate for Selenide plugin?

Was this page helpful?
0 / 5 - 0 ratings