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

element as first class citizen #696

Closed
lutzj82 opened this issue Aug 6, 2015 · 4 comments
Closed

element as first class citizen #696

lutzj82 opened this issue Aug 6, 2015 · 4 comments
Milestone

Comments

@lutzj82
Copy link

lutzj82 commented Aug 6, 2015

I'd like to see the element become more of a first class citizen. What I mean by this, is that instead of:

driver.setValue('#someinputEl', 'value');

I'd like to more of the following:

driver.element('#someinputEl').setValue('value');

It actually works for any command that takes a single argument (selector), such as getText or getValue
I just think it reads easier, and allows me to create functions representing each element.

Thanks

@christian-bromann
Copy link
Member

@lutzj82 this is almost the case. Thinks like

<div class="row">
  <div class="entry">
    <label>Product A</label>
    <button>Add to cart</button>
    <button>More Information</button>
  </div>
  <div class="entry">
    <label>Product B</label>
    <button>Add to cart</button>
    <button>More Information</button>
  </div>
  <div class="entry">
    <label>Product C</label>
    <button>Add to cart</button>
    <button>More Information</button>
  </div>
</div>
var row = yield client.element('.row .entry:nth-Child(1)');
yield row.click('button*=Add');

already work. I guess it should be possible to avoid the element argument if your last command call was the element command. It is just kinda hard to explain that to users like, you can do

client.click('#myelement');

but

var myelement = client.element('#myelement');
myelement.click();

works as well

@lutzj82
Copy link
Author

lutzj82 commented Aug 6, 2015

I get it...I guess since there was support for element chaining, it seems like a logical extension. I agree that I don't want it to be confusing though.

@christian-bromann christian-bromann modified the milestones: Icebox, Upcoming Sep 1, 2015
@christian-bromann
Copy link
Member

Moving into icebox. I get your point here but I don't 100% agree with you. One of the characteristics of E2E tests are that they get executed from the viewpoint of the user. Therefor:

The User -> clicks -> on elementA

which is exactly the reason why we have designed the API how it is:

browser. click ('#elementA')

However your argument makes sense when receiving attributes from certain elements (e.g. getCSSProperty, getLocation or isVisible). This could confuse other people though 😄 .. I will leave it as it is for now and keep it open so other people can comment on this.

@christian-bromann christian-bromann changed the title Scope commands to element (dot notation) element as first class citizen Sep 8, 2015
@christian-bromann
Copy link
Member

WebdriverIO (v4) now internally remembers the last result of a command. If you chain an element command with an action command it finds the element from the previous command and uses the result to execute the action. With that you can remove the selector (first parameter) and the command looks as simple as:

var elem = browser.element('#username');
elem.setValue('Max Mustermann');

which is basically the same thing as:

browser.element('#username').setValue('Max Mustermann');

or

browser.setValue('#username', 'Max Mustermann');

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

No branches or pull requests

2 participants