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

Support JS that ends with ; when using click. #1610

Merged
merged 1 commit into from Jul 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/core/engine/command/click.js
@@ -1,6 +1,16 @@
'use strict';

const log = require('intel').getLogger('browsertime.command.click');

function addClick(js) {
const trimmed = js.trim();
let script = `${trimmed}.click();`;
if (trimmed.endsWith(';')) {
script = `${trimmed.slice(0, -1)}.click();`;
}
return script;
}

class Click {
constructor(browser, pageCompleteCheck) {
this.browser = browser;
Expand Down Expand Up @@ -158,7 +168,7 @@ class Click {
*/
async byJs(js) {
try {
const script = `${js}.click();`;
const script = addClick(js);
await this.browser.runScript(script, 'CUSTOM');
} catch (e) {
log.error('Could not find element by JavaScript %s', js);
Expand All @@ -175,7 +185,7 @@ class Click {
*/
async byJsAndWait(js) {
try {
const script = `${js}.click();`;
const script = addClick(js);
await this.browser.runScript(script, 'CUSTOM');
return this.browser.extraWait(this.pageCompleteCheck);
} catch (e) {
Expand Down