diff --git a/app/src/textXPath.js b/app/src/textXPath.js index 7ed718f..59432f7 100644 --- a/app/src/textXPath.js +++ b/app/src/textXPath.js @@ -24,11 +24,13 @@ function getTextBasedXPath(element, tagName) { let c = getNumberOfXPath(t); if (c == 1) { XPATHDATA.push([0, 'Link Text', link.trim()]); + XPATHDATA.push([0, 'Link Text as XPath', t]); } else { let t = `//a[contains(.,'${link.trim()}')]`; let c = getNumberOfXPath(t); if (c == 1) { XPATHDATA.push([0, 'Link XPath', t]); + XPATHDATA.push([0, 'Link Text as XPath', t]); } } } @@ -38,6 +40,7 @@ function getTextBasedXPath(element, tagName) { let partialLink = `//a[contains(text(),'${link.trim()}')]`; if (getNumberOfXPath(partialLink) == 1) { XPATHDATA.push([0, 'Partial Link Text', link.trim()]) + XPATHDATA.push([0, 'Link Text as XPath', partialLink]); gotPartial = true; } else { link = element.textContent; @@ -53,12 +56,15 @@ function getTextBasedXPath(element, tagName) { hasSpace = link.match(/\s/g); if (hasSpace) { link = link.replace(/\s+/g, " "); - XPATHDATA.push([0, 'Link Text', link.trim()]) + XPATHDATA.push([0, 'Link Text', link.trim()]); + XPATHDATA.push([0, 'Link Text as XPath', temp]); } } else if (gotPartial == false && getNumberOfXPath(temp) == 1) { - XPATHDATA.push([0, 'Link Text', link.trim()]) + XPATHDATA.push([0, 'Link Text', link.trim()]); + XPATHDATA.push([0, 'Link Text as XPath', temp]); } else if (gotPartial == false && getNumberOfXPath(`//a[text()='${link.trim()}']`) == 1) { - XPATHDATA.push([0, 'Link Text', link.trim()]) + XPATHDATA.push([0, 'Link Text', link.trim()]); + XPATHDATA.push([0, 'Link Text as XPath', `//a[text()='${link.trim()}']`]); } } if (hasSpace) { diff --git a/manifest.json b/manifest.json index 69ca505..5c15462 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "short_name": "XPath finder", "description": "XPath Finder, simple and useful, open-source project", "author": "Koushik Chatterjee", - "version": "2.0.0", + "version": "2.0.1", "manifest_version": 2, "icons": { "16": "assets/16.png", diff --git a/option/option.html b/option/option.html index 63c7f6b..5c14cd4 100644 --- a/option/option.html +++ b/option/option.html @@ -2,171 +2,63 @@ - - - LetXPath Setting - - - - + + + LetXPath Setting + + + + - -
-
-
-
-
Snippet Configuration
-
Please select the default snippet to generate
-
-
-
-
- - - - - - -
-
-
Default Snippet has been changed to
-
-
-
-
-
-
Custom framework configuration
-
-
-
- -
-
- - + +
+
+
+
+
+
+
+

Code snippet

+

Configuration

+
+
+
+
+
+ +
+
+
+
+
+
+
Code sample
+
+
+
+                                
+                                    

hi am code

+
+
+
+
-
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
- -
-
-
-
-
-
-
-

- LetXPath gives you the following meta-data -

- 1. Locator Value - ${lc} - 2. Variable Name - ${vn} - 3. Method Name - ${mn} -

- Customize as per your requirements -

-

Example:

-
- - - - Protractor JS/TS - - -
-
-
private ${vn} = ${lc};
-async clickOn${mn}(){
-  await this.click(this.${vn})
-}
-
- Protractor JS/TS - Result -
-
private login = element(by.id('loginId'));
-async clickOnLogin(){
-  await this.click(this.login)
-}
-
-
-
-
- - - - Selenium JAVA/POM - - -
-
-
${lc} private WebElement ${vn}; 
-public void clickOn${mn}(){
-  this.click(this.${vn})
-}
-
- Selenium JAVA/POM - Result -
-
@FindBy(id= "loginId") private WebElement login;
-public void clickOnLogin(){
-  this.click(this.login);
-}
-
-
+
-
-
-
- -
+ + \ No newline at end of file diff --git a/option/option.js b/option/option.js index f4c7760..0d931b6 100644 --- a/option/option.js +++ b/option/option.js @@ -1,15 +1,19 @@ $(document).ready(function () { chrome.storage.local.get(['langID', 'customLang', 'clickvalue', 'sendvalue', 'textvalue', 'attrvalue'], (result) => { if (result.langID != undefined) { - // setStorage({ lang: radioValue, langID: radioID }); - document.getElementById(result.langID).checked = true; + const codeType = result.langID; + $("select").val(codeType).change(); + embedCodeSample(codeType); + setStorage({ langID: codeType }); } if (result.customLang != undefined) { - // setStorage({ lang: radioValue, langID: radioID }); - document.getElementById(result.customLang).checked = true; + const codeType = result.customLang; + $("select").val(codeType).change(); + embedCodeSample(codeType); + setStorage({ langID: codeType }); } else { - setStorage({ lang: 'Selenium - Java', langID: 'javas' }); - document.getElementById("javas").checked = true; + $("select").val(result.langID).change(); + setStorage({ langID: 'javas' }); } // set edited values in textarea if (result.clickvalue != undefined) { @@ -18,19 +22,13 @@ $(document).ready(function () { $("#text-s").val(result.textvalue) $("#attr-s").val(result.attrvalue) } - - - }); - $("input[type='radio'][name='snippetLanguage']").click(function () { - let ip = $("input[name='snippetLanguage']:checked"); - let radioValue = ip.val(); - let radioID = ip.attr("id"); - setStorage({ lang: radioValue, langID: radioID }); - let toast = document.querySelector('.toast') - toast.textContent = "Default Snippet has been changed to " + radioValue - toast.classList.remove('d-hide') - }) + $("select#snippets").change(function () { + var selectedvalue = $(this).children("option:selected").val(); + setStorage({ langID: selectedvalue }); + embedCodeSample(selectedvalue); + }); + $("form").on("submit", function () { let ip = $("input[name='cssnippetLanguage']:checked"); let customLang = ip.attr("id"); @@ -43,14 +41,43 @@ $(document).ready(function () { setStorage({ 'textvalue': textAct.val() }); let attrAct = $("#attr-s"); setStorage({ 'attrvalue': attrAct.val() }); - alert('Success') - // document.querySelector('.toast').classList.remove('d-hide'); - // document.querySelector(".toast").textContent = 'Success'; - // alert(clickAct.val(), sendAct.val(), textAct.val(), attrAct.val()) }) }); function setStorage(obj) { chrome.storage.local.set(obj, function () { }); +} + +function embedCodeSample(codetype) { + jQuery("#samplecode").empty(); + let code; + switch (codetype) { + case "playwrightJS": + code = `await page.locator("locator value");`; + break; + case "playwrightJava": + code = `page.locator("locator value");`; + break; + case "javas": + code = `driver.findElement(By.xpath("locator value"));`; + break; + case "py": + code = `driver.find_element(By.XPATH, "locator value")`; + break; + case "csharp": + code = `driver.FindElement(By.Xpath("locator value")); `; + break; + case "protractorjs": + code = `element(by.xpath("locator value"));`; + break; + case "custom": + code = `Custome framework`; + break; + default: + code = `driver.findElement(By.xpath("locator value"));`; + break; + } + jQuery("#samplecode").append(`${code}`); + } \ No newline at end of file diff --git a/option/option_backup.html b/option/option_backup.html new file mode 100644 index 0000000..63c7f6b --- /dev/null +++ b/option/option_backup.html @@ -0,0 +1,172 @@ + + + + + + + LetXPath Setting + + + + + + + +
+
+
+
+
Snippet Configuration
+
Please select the default snippet to generate
+
+
+
+
+ + + + + + +
+
+
Default Snippet has been changed to
+
+
+
+
+
+
Custom framework configuration
+
+
+
+ +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
+
+
+

+ LetXPath gives you the following meta-data +

+ 1. Locator Value - ${lc} + 2. Variable Name - ${vn} + 3. Method Name - ${mn} +

+ Customize as per your requirements +

+

Example:

+
+ + + + Protractor JS/TS + + +
+
+
private ${vn} = ${lc};
+async clickOn${mn}(){
+  await this.click(this.${vn})
+}
+
+ Protractor JS/TS - Result +
+
private login = element(by.id('loginId'));
+async clickOnLogin(){
+  await this.click(this.login)
+}
+
+
+
+
+ + + + Selenium JAVA/POM + + +
+
+
${lc} private WebElement ${vn}; 
+public void clickOn${mn}(){
+  this.click(this.${vn})
+}
+
+ Selenium JAVA/POM - Result +
+
@FindBy(id= "loginId") private WebElement login;
+public void clickOnLogin(){
+  this.click(this.login);
+}
+
+
+
+
+
+
+
+ +
+ + + \ No newline at end of file diff --git a/panelconfig.js b/panelconfig.js index 0024166..99ca8da 100644 --- a/panelconfig.js +++ b/panelconfig.js @@ -35,7 +35,6 @@ $(document).ready(function () { let range = document.createRange(); copyToClipBoard(range, from); $('select').prop('selectedIndex', 0); - // setTimeout(() => { from.classList.add('d-hide') }, 3000) }, 100); }); @@ -143,6 +142,12 @@ function generateSnippet(type, codeType, codeValue, vn, mn) { let code; let lang = result.langID; switch (lang) { + case "playwrightJS": + code = playwrightSnippetJS(type, codeType, codeValue, vn); + break; + case "playwrightJava": + code = playwrightSnippetJava(type, codeType, codeValue, vn); + break; case "javas": code = javaSnippet(type, codeType, codeValue, vn); break; @@ -166,17 +171,13 @@ function generateSnippet(type, codeType, codeValue, vn, mn) { code = javaSnippet(type, codeType, codeValue, vn); break; } - if (code === 'hide') { - document.querySelector('.toast').classList.add('d-hide'); - } - else { - document.querySelector(".toast").textContent = ''; - document.querySelector('.toast').classList.remove('d-hide'); - // let to = document.querySelector(".toast"); - let t = ` + + document.querySelector(".toast").textContent = ''; + document.querySelector('.toast').classList.remove('d-hide'); + // let to = document.querySelector(".toast"); + let t = `
${code}
` - $('.toast').append(t); - } + $('.toast').append(t); }); } function javaSnippet(type, codeType, codeValue, variable) { @@ -226,6 +227,103 @@ function javaSnippet(type, codeType, codeValue, variable) { } return str; } + +function playwrightSnippetJava(type, codeType, codeValue, variable) { + let str; + switch (codeType) { + case "CSS": + str = `page.locator("${codeValue}")`; + break; + case "Unique Class Atrribute": + str = `page.locator(".${codeValue}")`; + break; + case "Unique TagName": + str = `page.locator("${codeValue}")`; + break; + case "Link Text": + str = `page.locator("'${codeValue}'")`; + break; + case "Unique ID": + str = `page.locator("id=${codeValue}")`; + break; + case "Unique Name": + str = `page.locator("[name='${codeValue}']")`; + break; + case "Unique PartialLinkText": + str = `page.locator("a:has-text('${codeValue}'")`; + break; + default: + str = `page.locator("${codeValue}")`; + break; + } + switch (type) { + case "click": + str += `.click();` + break; + case "sendKeys": + str += `.type();` + break; + case "getAttribute": + str += `.getAttribute();` + break; + case "getText": + str += `.textContent();` + break; + default: + str = 'hide'; + break; + } + return str; +} + +function playwrightSnippetJS(type, codeType, codeValue, variable) { + let str; + switch (codeType) { + case "CSS": + str = `await page.locator("${codeValue}")`; + break; + case "Unique Class Atrribute": + str = `await page.locator(".${codeValue}")`; + break; + case "Unique TagName": + str = `await page.locator("${codeValue}")`; + break; + case "Link Text": + str = `await page.locator("'${codeValue}'")`; + break; + case "Unique ID": + str = `await page.locator("id=${codeValue}")`; + break; + case "Unique Name": + str = `await page.locator("[name='${codeValue}']")`; + break; + case "Unique PartialLinkText": + str = `await page.locator("a:has-text('${codeValue}'")`; + break; + default: + str = `await page.locator("${codeValue}")`; + break; + } + switch (type) { + case "click": + str += `.click();` + break; + case "sendKeys": + str += `.type();` + break; + case "getAttribute": + str += `.getAttribute();` + break; + case "getText": + str += `.textContent();` + break; + default: + str = 'hide'; + break; + } + return str; +} + // TODO: test snippets values function jsSnippet(type, codeType, codeValue, variable) { diff --git a/popup/popup.html b/popup/popup.html index 97ff834..dc34dd2 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -59,7 +59,7 @@

- + @@ -70,7 +70,7 @@

Privacy Policy

-

Copyright © 2020 Koushik Chatterjee +

Copyright © 2022 Koushik Chatterjee