SSR - Ignore intermediate chained method calls

Answered

Hi Everyone,

Context

There is a java test library called FluentLenium which I'm trying to create an SSR Search template for. It has an assertj support module with the class called FluentLeniumAssertions, which have assertions for its FluentPage type objects.

Its hasExpectedUrl() method call is invalid if the parameter FluentPage object (any descendants of it) doesn't have the @PageUrl annotation applied on the class itself.

An example call would look like this:

FluentLeniumAssertions.assertThat(fluentPage).hasExpectedUrl();

Search template

I so far managed to put together the following template:

org.fluentlenium.assertj.FluentLeniumAssertions.assertThat($FluentPage$).hasExpectedUrl();

$FluentPage$:

  • Type filter: org.fluentlenium.core.FluentPage - Within type hierarchy
  • Script filter: !FluentPage.getType().resolve().hasAnnotation("org.fluentlenium.core.annotation.PageUrl")

It works fine for a single method call after assertThat():

FluentLeniumAssertions.assertThat(fluentPage).hasExpectedUrl();

but not for

FluentLeniumAssertions.assertThat(fluentPage).hasExpectedElements().hasExpectedUrl();

which has an other chained method call before.

 

I was trying to add another template variable to ignore the rest of the chained calls:

org.fluentlenium.assertj.FluentLeniumAssertions.assertThat($FluentPage$).$assertion$().hasExpectedUrl();

but in that case Count filter is not a selectable option for the $assertion$ variable.

I also tried it as

org.fluentlenium.assertj.FluentLeniumAssertions.assertThat($FluentPage$).$assertion$.hasExpectedUrl();

but in this case $assertion$ is handled rather as a field, than a method and Count filter is limited to the [0, 1] range.

 

I don't really have another idea how I could adjust the template so that it works with additional chained method calls as well.

I would appreciate some help.

0
4 comments
Official comment

Sorry there is no way to achieve this in a single query with SSR at this moment. If you are trying to create an Structural Search inspection, you could add several patterns instead. For example 4 different patterns, with 0 to 3 method calls in between.

If you are just searching your project you could split the search into two separate searches. First find all `hasExpectedUrl()` calls:

 

$qualifier$.hasExpectedUrl()

 

And find the relevant `assertThat()` calls in the scope "Previous Search Results":

 

org.fluentlenium.assertj.FluentLeniumAssertions.assertThat($FluentPage$)

 

 

Please file a feature request, if you think there should be an easier to search these kinds of method chains: https://youtrack.jetbrains.com/

 

Bas

Yes, I'm creating a permanent Search inspection, not just searching in my project, so I'll go with the X number of different patterns for now.

As for searching in the "Previous Search Results" scope, that is interesting, I didn't know about that.

 

Thanks for your help.

0

Thank you for this great website you have created!

https://ijnspector.wordpress.com/

 

Bas

0

I really enjoy experimenting with the tool. Thank you very much.

0

Please sign in to leave a comment.