Skip to content

Commit

Permalink
Update click.js for relative selectors (#2747)
Browse files Browse the repository at this point in the history
* Update click.js for relative selectors

If a Relative Selector is passed in as the third argument inside of click(), it doesn't actually make it down to waitAndGetActionableElement.

 We found that `await click(element, options, within(withinElement))`  doesn't search in the "within" element

Signed-off-by: DCoomer <[email protected]>

* Updated Unit Test for #2747

Signed-off-by: DCoomer <[email protected]>

* Updated Unit Test Formatting for #2747

Signed-off-by: DCoomer <[email protected]>

* Updated Unit Test Formatting for #2747

Signed-off-by: DCoomer <[email protected]>

* Updated Unit Test HTML  and formatting for #2747

Signed-off-by: DCoomer <[email protected]>

---------

Signed-off-by: DCoomer <[email protected]>
Signed-off-by: DCoomer <[email protected]>
  • Loading branch information
DCoomer authored Jan 2, 2025
1 parent 6645c6d commit da6cb92
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/actions/click.js
Original file line number Diff line number Diff line change
@@ -49,11 +49,11 @@ async function simulateInputEvents(options) {
}

async function click(selector, options = {}, ...args) {
let allOptions = options;
let allOptions = args;
if (options instanceof RelativeSearchElement) {
allOptions = [options].concat(args);
}
const clickOptions = setClickOptions(allOptions);
const clickOptions = setClickOptions(options);
clickOptions.noOfClicks = clickOptions.clickCount || 1;

if (isSelector(selector) || isString(selector) || isElement(selector)) {
16 changes: 16 additions & 0 deletions test/unit-tests/click.test.js
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ describe(test_name, () => {
<input onclick="displayText('Click works with text as value.')" value="Text as value"/><br/>
<input onclick="displayText('Click works with text as type.')" type="Text as type"/><br/>
<span onclick="displayText('Click works with proximity selector.')">Click with proximity</span>
<span onclick="displayText('Click works with proximity selector and options object.')">Click with proximity and options object</span>
<div onclick="displayText('Click works with text accross element.')">
Text <span>accross</span> elements
</div>
@@ -154,6 +155,21 @@ describe(test_name, () => {
});
});

describe("With proximity selector and options object", () => {
it("should click", async () => {
await click(
"Click with proximity and options object",
{ waitForNavigation: true },
below("Proximity marker"),
);
expect(
await text(
"Click works with proximity selector and options object.",
).exists(),
).to.be.true;
});
});

describe("Text accross element", () => {
it("should click", async () => {
await click("Text accross elements");

2 comments on commit da6cb92

@DCoomer
Copy link
Contributor Author

@DCoomer DCoomer commented on da6cb92 Jan 2, 2025

Choose a reason for hiding this comment

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

@NivedhaSenthil Do I need to bump the version number in package.json?

@NivedhaSenthil
Copy link
Member

Choose a reason for hiding this comment

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

Oops yes merged before the version update, thanks for creating another PR

Please sign in to comment.