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 missing isSelected command to new Element API. #4038

Merged

Conversation

dikwickley
Copy link
Contributor

@dikwickley dikwickley commented Feb 22, 2024

fixes: #4036
Thanks in advance for your contribution. Please follow the below steps in submitting a pull request, as it will help us with reviewing it quicker.

  • Create a new branch from master (e.g. features/my-new-feature or issue/123-my-bugfix);
  • If you're fixing a bug also create an issue if one doesn't exist yet;
  • If it's a new feature explain why do you think it's necessary. Please check with the maintainers beforehand to make sure it is something that we will accept. Usually we only accept new features if we feel that they will benefit the entire community;
  • Please avoid sending PRs which contain drastic or low level changes. If you are certain that the changes are needed, please discuss them beforehand and indicate what the impact will be;
  • If your change is based on existing functionality please consider refactoring first. Pull requests that duplicate code will most likely be ignored;
  • Do not include changes that are not related to the issue at hand;
  • Follow the same coding style with regards to spaces, semicolons, variable naming etc.;
  • Always add unit tests - PRs without tests are most of the times ignored.

@CLAassistant
Copy link

CLAassistant commented Feb 22, 2024

CLA assistant check
All committers have signed the CLA.

@garg3133
Copy link
Member

@dikwickley Please refer to #4033 (comment) for tests.

lib/api/web-element/commands/isSelected.js Outdated Show resolved Hide resolved
lib/api/web-element/commands/isSelected.js Outdated Show resolved Hide resolved
types/web-element.d.ts Outdated Show resolved Hide resolved
@dikwickley
Copy link
Contributor Author

dikwickley commented Feb 22, 2024

@garg3133 thanks for the review

Added the test case as well.
I took reference from here
image

Also as for the type of isSelected() in web-elements.d.ts, I am a little confused as to what you meant by this

isSelected would returns an instance of ScopedValue.
Is this what you meant by above

isSelected(): ElementValue<boolean>;

@garg3133
Copy link
Member

Also as for the type of isSelected() in web-elements.d.ts, I am a little confused

Yeah, sorry. ElementValue is what I meant.

Added the test case as well.
I took reference from here

You can take a reference from there but you need to keep the format of the test similar to what we have in test/src/api/commands/web-element/testGetText.js file. You just need to change the command, mock and result value in there. Also, response in mock should only need to have the value property, status and sessionId are not needed.

@garg3133
Copy link
Member

Also, can you please sign the CLA?

dikwickley and others added 3 commits February 23, 2024 19:48
Co-authored-by: Priyansh Garg <priyanshgarg30@gmail.com>
Co-authored-by: Priyansh Garg <priyanshgarg30@gmail.com>
@dikwickley
Copy link
Contributor Author

hey @garg3133 I have updated the tests and signed the CLA.

Copy link
Member

@vaibhavsingh97 vaibhavsingh97 left a comment

Choose a reason for hiding this comment

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

We are nearly there; I would recommend adding a few negative tests as well.

lib/api/web-element/commands/isSelected.js Outdated Show resolved Hide resolved
dikwickley and others added 2 commits February 25, 2024 23:47
Co-authored-by: Vaibhav Singh <singh.vaibhav2011@gmail.com>
@dikwickley
Copy link
Contributor Author

@vaibhavsingh97 let me know if anything else is needed

@dikwickley dikwickley requested a review from garg3133 February 26, 2024 07:48
@dikwickley
Copy link
Contributor Author

there is a test failing for windows (18.x)
it doesn't seem to belong to any files I have created/updated

 ️TEST FAILURE (1.347s):  
   - 1 assertions failed; 0 passed
   - 1 skipped

   × 1) sample

   – demoTest (171ms)

   → ✖ NightwatchAssertError
   Testing if element <#weblogin> is present in 10ms - expected "is present" but got: "not present" (47ms)

    Error location:
    D:\a\nightwatch\nightwatch\test\sampletests\withfailures\sample.js:14
    ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
     12 |   demoTest(client) {
     13 |     client.url('http://localhost')
     14 |       .assert.elementPresent('#weblogin') 
     15 |       .assert.elementPresent('#badElement')
     16 |       .assert.elementPresent('#webLogin')
     
    ```

@garg3133
Copy link
Member

@dikwickley That's just a flaky test, ignore it. It will automatically pass on a re-run.

Copy link
Member

@garg3133 garg3133 left a comment

Choose a reason for hiding this comment

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

This PR is almost complete, just a feedback on tests:

Like I said before, the format of the test needs to be same as test/src/api/commands/web-element/testGetText.js because we want to test everything we tested for .getText() command in .isSelected() test as well.

So, the test file for isSelected() should have all the 4 test cases that are present in the test file of getText(), you just need to replace getText with isSelected there along with a bunch of other things like the mocks, how to interpret results, etc.

For example, the first test case will look as the following:

const resultPromise = this.client.api.element('#signupSection').isSelected();
    assert.strictEqual(resultPromise instanceof Element, false);
    assert.strictEqual(typeof resultPromise.find, 'undefined');

    assert.strictEqual(resultPromise instanceof Promise, false);
    assert.strictEqual(typeof resultPromise.then, 'function');

    const result = await resultPromise;
    assert.strictEqual(result instanceof WebElement, false);
    assert.strictEqual(result, true);

    const resultValue = await resultPromise.value;
    assert.strictEqual(resultValue, true);

test/src/api/commands/web-element/testIsSelected.js Outdated Show resolved Hide resolved
test/src/api/commands/web-element/testIsSelected.js Outdated Show resolved Hide resolved
@dikwickley dikwickley force-pushed the issue/4036-add-missing-isselected branch from 2cf3ee3 to f5efa74 Compare February 26, 2024 11:22
@dikwickley dikwickley requested a review from garg3133 February 26, 2024 11:26
Copy link
Member

@garg3133 garg3133 left a comment

Choose a reason for hiding this comment

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

One last bit for test: add a test case to test the .assert available on the command (see 4th test case of testGetText.js file).

You only need to text .assert.eqauls and .assert.not.equals in this case.

test/src/api/commands/web-element/testIsSelected.js Outdated Show resolved Hide resolved
@dikwickley dikwickley requested a review from garg3133 February 26, 2024 12:15
@garg3133 garg3133 changed the title added missing command isSelected to new Element API Add missing isSelected command to new Element API. Feb 26, 2024
@garg3133
Copy link
Member

@AutomatedTester This PR is ready to be merged now.

@Jai0401 Jai0401 mentioned this pull request Feb 27, 2024
8 tasks
@garg3133 garg3133 merged commit 8462c16 into nightwatchjs:main Feb 28, 2024
17 checks passed
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.

Add missing isSelected command to new Element API
4 participants