Skip to content
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

Potential bug with Text.ofAll() #603

Closed
Ijee opened this issue Jun 23, 2020 · 8 comments
Closed

Potential bug with Text.ofAll() #603

Ijee opened this issue Jun 23, 2020 · 8 comments

Comments

@Ijee
Copy link

Ijee commented Jun 23, 2020

As I mentioned on gitter currently Text.ofAll() does not return an array when your target points towards a select and you want to get the option text. Instead it will return a string that contains new line breaks as \n.

<html>
  <select>
    <h1>Category</h1>
    <option>Feature</option>
    <option>Bug</option>
   </select>
</html>

Here text.ofAll(Target.the('Category select').located(by.css('html > select')); would currently only return

Feature\nBug\n as the actual value as a string on the site.

It only does that currently for html selects and works for every other html strcuture I used it on.

I added a reproduceable unit test on my fork here

In the meantime can I somehow get the values myself and transform them to an array so I can easily compare them for my tests? As I have quite a lot of those tests spread around in one of my test repos a lot of tests currently fail.

@Ijee
Copy link
Author

Ijee commented Jun 23, 2020

I haven't 100% confirmed it yet but Text.of() also seems to not get the actual selected visible text from a target that points to a select.

@jan-molak
Copy link
Member

Hi @Ijee,

Thanks for providing a test case!

Given a HTML snippet like in the example above:

<html>
  <select>
    <h1>Category</h1>
    <option>Feature</option>
    <option>Bug</option>
   </select>
</html>

and the question:

Text.ofAll(Target.the('Category select').located(by.css('html > select'));

what you're effectively saying is "give me text of all the select elements".

However, because there's only one select element, you're being given the text that element contains, which is the visible text of all its nested elements - so h1 and options.

Could you try adding option to the selector and let me know if that helps:

Text.ofAll(Target.the('Category select').located(by.css('html > select option'));

Thanks,
Jan

@Ijee
Copy link
Author

Ijee commented Jul 3, 2020

So the thing is.
Text.of(Target.the('Category select').located.(by.css('html > select'));
returns an array that returns the visible text for all visible options. Whereas I expected that Text.of() to just return the current visible selected option text and Text.ofAll(Target.the('Category select').located.(by.css('html > select')); to return an array with all visible option texts.

Hope that makes sense. I am not sure that I really want different Targets for the same HTML Element when I want all visible text options or just the selected one.

@nbarrett
Copy link
Contributor

nbarrett commented Jul 3, 2020

Hi @Ijee - maybe this PR might provide you with more flexibility in getting the exact text you want? Hopefully will be merged soon @jan-molak?

@Ijee
Copy link
Author

Ijee commented Jul 3, 2020

@nbarrett that really looks like what I was looking for / expected. I like it!

I haven't taken a closer look but it does work with only a select as a target, aye?

@Ijee
Copy link
Author

Ijee commented Sep 10, 2020

So it's been a year and I still have this problem.

The thing is that I know what you mean but I don't see myself writing multiple targets for selects. I just don't see why that is necessary. This way I'd have to have a different target if I wanted to select a specific value / option text and another one if I wanted to check the currently selected value or am I missing something?

I got quite a lot of problems with my tests for a while now and I am basically still stuck on the old 1.x version due to a big amount of tests just failing..

I mean yeah it is kind of my problem because in the old version I did a lot of custom Questions to get the desired result like this

const optionsQuestion = Question.about(
            'all select option texts',
            () => targetElementFinder.map(ele => ele.getText().then(val => val.trim())) as PromiseLike<string[]>,
        );

This Question basically just got all the option text and I could simply assert them with my test case (it is obviously not the whole code).

If I knew how to make them work again I'd do so in a hearbeat.

@nbarrett
Copy link
Contributor

Hey @Ijee - have you tried the latest version of serenity-js since #373 has been merged? The product now has great support for single / multiple options / text.

@jan-molak
Copy link
Member

Closing the ticket since like @nbarrett has mentioned - Serenity/JS has added an interaction to Select and a question about Selected.

Hope they'll make your life easier, @Ijee :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants