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

Add support for page object-formatted object-based selectors #1156

Merged
merged 1 commit into from
Oct 5, 2016

Conversation

senocular
Copy link
Contributor

@senocular senocular commented Aug 19, 2016

(Partial implementation of the original #1116)

Adds support for optional, object-based selector values in commands using the format used by page elements. ex:

// before:
browser.getText('#foo', function(result){});

// now (optionally):
browser.getText({selector:'#foo', locateStrategy:'css selector'}, function(result){});

Also noticed this seems to be an exact implementation of #720.

@GBeauny
Copy link

GBeauny commented Aug 22, 2016

@senocular This fix could be on the next release? Thanks Guys.
There is also this issue related: #903.

@beatfactor
Copy link
Member

something happened to the tests, it seems to have crashed half way.

@senocular
Copy link
Contributor Author

This has a dependency on #1155 and won't work until that's in

@beatfactor
Copy link
Member

Ah yes. Would it be possible to merge the other PR into this one?

@senocular
Copy link
Contributor Author

Yeah I can work on that

@senocular senocular changed the title [MERGE AFTER #1155] Add support for page object-formatted object-based selectors Add support for page object-formatted object-based selectors Sep 18, 2016
@senocular
Copy link
Contributor Author

Merged with #1155 and fixed some tests. @drptbl, if you're still around and could give this a whirl, making sure nothing existing breaks and it works as you might expect, that would be great.

@beatfactor as with before, I can squash to one commit if/when it goes in.

@beatfactor
Copy link
Member

Cool, I'll try to take another look here. Thanks.

@senocular
Copy link
Contributor Author

There was an issue with error messaging when using selector objects in command calls. For example if you had something like:

    browser.getText({selecto:'div', locateStrategy:'css selector'}, function (result) {
        console.log('My div text is ', result.value);
    });

The error message would be:

Error while running getText command: No selector property for element "(anonymous)". Instead found properties: locateStrategy

The first problem being that its picking up the confusing "(anonymous)" text. But I think more importantly, you're losing the problem key. selector was misspelled as selecto and that was getting stripped because the object passed in wasn't the same object that was making it to the constructor where the error is getting generated.

With the latest commit, if Element.fromSelector() gets an object value, it keeps that value, passing it into the constructor so the full definition can be seen. Additionally the error message is smarter checking for a name, using the old classtype + name messaging when in a page object/section, and using a generic "selector object" text when used in a selector context. So now the error message is:

Error while running getText command: No selector property for selector object. Instead found properties: selecto, locateStrategy

@beatfactor
Copy link
Member

Hey, sorry for the slow progress here. I think this looks good, but could you also add/update an example testcase with how will this be used? Also could you move all the selector tests inside a folder in src/api/element-selectors? Thanks.

@senocular
Copy link
Contributor Author

...could you also add/update an example testcase with how will this be used?

@beatfactor Can you be more specific about this? Thanks.

@beatfactor
Copy link
Member

I was thinking of updating one of the sample tests in the examples folder with showing how this can be used, but I think we can do that when the original #1116 is fully implemented?

@senocular
Copy link
Contributor Author

@beatfactor yeah, as is, I don't think anyone would need to use this right now. It doesn't add much new other than a new syntax for the same inputs. With index support, I'll be sure to add an example.

Copy link
Member

@beatfactor beatfactor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, can you squash the commits please? Then I will merge it to master. Thanks, and once again sorry for taking so long to review.

@senocular
Copy link
Contributor Author

Done

@senocular
Copy link
Contributor Author

Hold on, I think the tests didn't make the commit...

@senocular
Copy link
Contributor Author

tests confirmed added: https://github.com/nightwatchjs/nightwatch/pull/1156/files#diff-3523a9a2061901f4ab5d9fba67c6da9e

And passing, so that is also a good sign

@beatfactor beatfactor merged commit 74ea6cc into nightwatchjs:master Oct 5, 2016
@laurensclaessen
Copy link

laurensclaessen commented Dec 21, 2016

Hi, thanks for this feature! It's very useful!

@beatfactor, any thoughts on when this will be released in a tag?

@humphreyn
Copy link

@beatfactor Any idea when this is going to be released?

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

Successfully merging this pull request may close these issues.

None yet

5 participants