darcy-framework/darcy-web

Failure Trace

Closed this issue · 5 comments

Imagine a HomePage with a method:

public LoginPage clickLoginLink() {
    return after(loginLink::click)
            .expect(transition().to(new LoginPage()))
            .waitUpTo(2, ChronoUnit.MINUTES);
}

Imagine also that the LoginPage in question has some required webelement field with wrong selector.

When in test one tries to call this method, test fails with a very strange failure trace:

com.redhat.synq.TimeoutException: Timed out after PT2M waiting for event to occur.
Event occurs when action is finished (my.project.darcy.HomePage$$Lambda$49/30327649@5471)
and then the item under examination is a View that is loaded in context, com.redhat.darcy.webdriver.WebDriverBrowser@e24091,
however the last examined result was, "my.project.darcy.LoginPage@ceadd4",
which is not a View that is loaded in context, com.redhat.darcy.webdriver.WebDriverBrowser@e24091 (as determined by polling every PT1S)

Instead of NoSuchElementException, such an uninformative text making it extremely hard to track the real cause of failure.

So am I doing something wrong or is it a framework's problem?

Hi there! Thanks for trying out the framework! So, you're not doing anything wrong, we definitely want to improve the error handling around when an element isn't found. There's been some discussion around this here: darcy-framework/darcy-ui#55 . Unfortunately, based on the API of Views in darcy, this proved to be somewhat difficult without fancier reflection done under the hood. I was trying to stay away from having to do that to achieve this, but we'll probably have to resort to that. It's worth the complexity to achieve the obvious value in better error reporting in these scenarios.

Apologies for the confusion. Please watch that issue, there should be some movement on improving this soon.

Closing because we have this tracked in the above linked issue (darcy-framework/darcy-ui#55). Please don't interpret this as lack of caring, let's continue the conversation there. Thanks!

Thank you for the reply and sorry for me not noticing the existing discussion.

And, by the way, yet another exception that I encountered:

com.redhat.synq.ConditionEvaluationException: com.redhat.darcy.ui.NoRequiredElementsException: No fields that implement View, Element, Findable, or List of those types, were configured to be required. Configure required elements by use of @require, @RequireAll, and @NotRequired annotations.

Isn't it a bit too restrictive? What if a page consists solely of modules and no fields of its own are necessary?

The issue with not having any required fields is that there is no way to tell if the view is loaded or not -- you should give some indication that we successfully got to that page and it is done loading. Darcy always blocks waiting for a view to load, and it assumes it is programmer error if there's no explicit condition to check for.

If you need more complicated logic (like you want one of a few possible options), there are a few things you can do. First, you can require a List of "Views, Elements, or Findables" as the exception suggests. So if you have a page where one of a few possibilities is expected to be present on the page when it is done loading, that's a good option.

You can also always override public boolean isLoaded() which is part of the View API, and implemented for you by AbstractView (which is what is using reflection to read your view's fields for required elements by default). But I'd recommend only doing that for scenarios that could not be naturally expressed with annotations.

Let me know if that helps!

Thank you, Alec, for clarification, that was helpful.