Skip to content

Commit 0ecd07d

Browse files
Merge pull request #99 from apokryfos/improve-webdriver
Improvements to the webdriver autogenrated code
2 parents 28c6384 + 43c1a23 commit 0ecd07d

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

panel/js/katalon/newformatters/webdriver.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ const newWebDriver = function (scriptName) {
1414
let _scriptName = scriptName || "";
1515
const locatorType = {
1616
xpath: (target) => {
17-
return `'${target.replace(/'/g, "\\\'")}'`;
17+
return `\`${target.replace(/'/g, "\\\'")}\``;
1818
},
1919
css: (target) => {
20-
return `'${target.replace(/"/g, "\'")}'`;
20+
return `\`${target.replace(/"/g, "\'")}\``;
2121
},
2222
id: (target) => {
23-
return `'#${target.replace(/"/g, "\'")}'`;
23+
return `\`#${target.replace(/"/g, "\'")}\``;
2424
},
2525
link: (target) => {
26-
return `'=${target.replace(/"/g, "\'")}'`;
26+
return `\`=${target.replace(/"/g, "\'")}\``;
2727
},
2828
name: (target) => {
29-
return `'[name="${target.replace(/"/g, "\'")}"]'`;
29+
return `\`[name="${target.replace(/"/g, "\'")}"]\``;
3030
},
3131
tag_name: (target) => {
32-
return `'${target.replace(/"/g, "\'")}'`;
32+
return `\`${target.replace(/"/g, "\'")}\``;
3333
}
3434
};
3535

@@ -61,6 +61,10 @@ const newWebDriver = function (scriptName) {
6161
"const el__STEP_ = $(_BY_LOCATOR_);\n" +
6262
"\t\tel__STEP_.waitForClickable();\n" +
6363
"\t\tel__STEP_.click();",
64+
"check":
65+
"const el__STEP_ = $(_BY_LOCATOR_);\n" +
66+
"\t\tif (!el__STEP_.isSelected()) " +
67+
"el__STEP_.click();\n",
6468
"doubleClick": "$(_BY_LOCATOR_).doubleClick();",
6569
"doubleClickAndWait":
6670
"const el__STEP_ = $(_BY_LOCATOR_);\n" +
@@ -73,7 +77,7 @@ const newWebDriver = function (scriptName) {
7377
"\t\tel__STEP_.setValue('_VALUE_');",
7478
"pause": "browser.pause(_VALUE_);",
7579
"refresh": "browser.refresh();",
76-
"sendKeys": "await $(_BY_LOCATOR_).sendKeys(_SEND_KEY_);",
80+
"sendKeys": "$(_BY_LOCATOR_).setValue(`_VALUE_`);",
7781
"sendKeysAndWait":
7882
"const el__STEP_ = $(_BY_LOCATOR_);\n" +
7983
"\t\tel__STEP_.waitForClickable();\n" +
@@ -87,6 +91,7 @@ const newWebDriver = function (scriptName) {
8791
"assertText": "expect( $(_BY_LOCATOR_)).toHaveTextContaining(`_VALUE_STR_`);",
8892
"assertTitle": "expect( browser).toHaveTitle(`_VALUE_STR_`);",
8993
"assertValue": "expect( $(_BY_LOCATOR_)).toHaveValueContaining(`_VALUE_STR_`)",
94+
"assertVisible": "expect($(_BY_LOCATOR_)).toBeDisplayed()",
9095
"waitForAlertPresent":
9196
"browser.waitUntil(function() {\n" +
9297
"\t\t\treturn browser.getAlertText()\n" +
@@ -102,9 +107,9 @@ const newWebDriver = function (scriptName) {
102107
};
103108

104109
const header =
105-
"var assert = require('assert');\n\n" +
110+
"/* This uses @webdriverio/sync */\n\n" +
106111
"describe('_SCRIPT_NAME_', function() {\n\n" +
107-
"\tit('should do something', function() {\n";
112+
"\tit('should _SCRIPT_NAME_', function() {\n";
108113

109114
const footer = "\t});\n\n});";
110115

@@ -162,7 +167,7 @@ const newWebDriver = function (scriptName) {
162167
let selectorStr = target.substr(target.indexOf("=") + 1, target.length);
163168
let locatorFunc = locatorType[locType];
164169
if ( typeof (locatorFunc) == 'undefined' ) {
165-
return `'${target.replace(/'/g, '"')}'`;
170+
return `\`${target.replace(/'/g, '"')}\``;
166171
}
167172

168173
return locatorFunc(selectorStr);

0 commit comments

Comments
 (0)