Skip to content

Commit

Permalink
Update the fill input text function to be by label instead of a speci…
Browse files Browse the repository at this point in the history
…fic attribute #142
  • Loading branch information
TasneemNatshah committed Jul 11, 2024
1 parent eeb7070 commit 2b1b340
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/test--then--i-should--not--see-text-in-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
<h1>Login</h1>

<div class="container">
<p><label for="uname"><b>Username</b></label></p>
<p><label for="uname">Username</label></p>
<p><input id="uname" class="unamecss" type="text" placeholder="Enter Username" name="username"></p>

<p><label for="pword"><b>Password</b></label></p>
<p><label for="pword">Password</label></p>
<p><input id="pword" class="pwordcss" type="password" placeholder="Enter Password" name="password"></p>

<p><input id="reset" type="reset" value="Reset" /><input id="btnLogin" class="btnLogin" name="btnLogin" type="button" value="Login" onclick="onClick()" /></p>
Expand Down
4 changes: 2 additions & 2 deletions examples/test--then--i-should--see-text-in-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
<h1>Login</h1>

<div class="container">
<p><label for="uname"><b>Username</b></label></p>
<p><label for="uname">Username</label></p>
<p><input id="uname" class="unamecss" type="text" placeholder="Enter Username" name="username"></p>

<p><label for="pword"><b>Password</b></label></p>
<p><label for="pword">Password</label></p>
<p><input id="pword" class="pwordcss" type="password" placeholder="Enter Password" name="password"></p>

<p><input id="reset" type="reset" value="Reset" /><input id="btnLogin" class="btnLogin" name="btnLogin" type="button" value="Login" onclick="onClick()" /></p>
Expand Down
4 changes: 2 additions & 2 deletions examples/test--when--i-fill-in.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
<h1>Login</h1>

<div class="container">
<p><label for="uname"><b>Username</b></label></p>
<p><label for="uname">Username</label></p>
<p><input id="uname" class="unamecss" type="text" placeholder="Enter Username" name="username"></p>

<p><label for="pword"><b>Password</b></label></p>
<p><label for="pword">Password</label></p>
<p><input id="pword" class="pwordcss" type="password" placeholder="Enter Password" name="password"></p>

<p><input id="btnLogin" class="btnLogin" name="btnLogin" type="button" value="Login" onclick="onClick()"></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Feature: An example to test whether an element contains a certain text or not

Scenario: Check an element if it contains a specific text
Given I am on "/test--then--i-should--not--see-text-in-element.html"
And I fill in "#uname" with "user1"
And I fill in "#pword" with "1234"
When I fill in "Username" with "user1"
And I fill in "Password" with "1234"
Then I should see "user1" in the "#uname" element
When I fill in "#uname" with:
And I fill in "#pword" with:
Then I should not see "user1" in the "#uname" element

Scenario: Check an element if it does not contain a specific text
Given I am on "/test--then--i-should--not--see-text-in-element.html"
And I fill in "#uname" with "user2"
And I fill in "Username" with "user2"
Then I should not see "user1" in the "#uname" element
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Feature: An example to test if the field contains certain value

Scenario: Check field if has a particular value or not
Given I am on "/test--then--i-should--not--see-text-in-element.html"
And I fill in "#uname" with "user1"
And I fill in "Username" with "user1"
Then the "#uname" field should contain "user1"
When I press "Reset" by attr
And I fill in "#uname" with "user2"
And I fill in "Username" with "user2"
Then the "#uname" field should not contain "user1"
4 changes: 2 additions & 2 deletions tests/features/test--when--i-fill-in.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ I want to be able to fill input text with value

Scenario: Check fill in input field with value
Given I am on "/test--when--i-fill-in.html"
When I fill in "#uname" with "John Smith"
When I fill in "#pword" with "1234"
When I fill in "Username" with "John Smith"
When I fill in "Password" with "1234"
When I press "Login" by attr
Then I should see "You enter Username: John Smith and Password: 1234"

Expand Down
5 changes: 4 additions & 1 deletion tests/step-definitions/webship.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ When(/^(I|we)* reload the page$/, function (pronoundCase) {
*
*/
When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (pronoundCase, field, value) {
browser.setValue(field, value);
const elementField = browser.element.findByText(field);
browser.getAttribute(elementField, 'for', function (eleAttribute) {
return browser.setValue('#' + eleAttribute.value, value);
});
});

/**
Expand Down

0 comments on commit 2b1b340

Please sign in to comment.