Skip to content

Commit 8772c00

Browse files
author
David Haeffner
committed
Added improved string escaping
1 parent b47e051 commit 8772c00

File tree

30 files changed

+164
-70
lines changed

30 files changed

+164
-70
lines changed

packages/code-export-java-junit/__test__/src/__snapshots__/index.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class LoginTest {
4141
driver.findElement(By.id(\\"username\\")).sendKeys(\\"tomsmith\\");
4242
driver.findElement(By.id(\\"password\\")).sendKeys(\\"SuperSecretPassword!\\");
4343
driver.findElement(By.cssSelector(\\"#login button\\")).click();
44-
assertThat(driver.findElement(By.cssSelector(\\".flash.success\\")).getText(), is(\\"You logged into a secure area!\\\\\\\\n×\\"));
44+
assertThat(driver.findElement(By.cssSelector(\\".flash.success\\")).getText(), is(\\"You logged into a secure area!\\\\n×\\"));
4545
}
4646
@Test
4747
public void invalidcredentials() {
@@ -50,7 +50,7 @@ public class LoginTest {
5050
driver.findElement(By.id(\\"username\\")).sendKeys(\\"blah\\");
5151
driver.findElement(By.id(\\"password\\")).sendKeys(\\"blah\\");
5252
driver.findElement(By.cssSelector(\\"#login button\\")).click();
53-
assertThat(driver.findElement(By.id(\\"flash\\")).getText(), is(\\"Your username is invalid!\\\\\\\\n×\\"));
53+
assertThat(driver.findElement(By.id(\\"flash\\")).getText(), is(\\"Your username is invalid!\\\\n×\\"));
5454
}
5555
}
5656
"
@@ -388,7 +388,7 @@ public class LoginTest {
388388
driver.findElement(By.id(\\"username\\")).sendKeys(\\"tomsmith\\");
389389
driver.findElement(By.id(\\"password\\")).sendKeys(\\"SuperSecretPassword!\\");
390390
driver.findElement(By.cssSelector(\\"#login button\\")).click();
391-
assertThat(driver.findElement(By.cssSelector(\\".flash.success\\")).getText(), is(\\"You logged into a secure area!\\\\\\\\n×\\"));
391+
assertThat(driver.findElement(By.cssSelector(\\".flash.success\\")).getText(), is(\\"You logged into a secure area!\\\\n×\\"));
392392
}
393393
}
394394
"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`location code emitter should escape quotes in locator strings 1`] = `"By.cssSelector(\\"a[title=\\"escaped\\"]\\")"`;

packages/code-export-java-junit/__test__/src/location.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ describe('location code emitter', () => {
7373
it('should escape quotes in locator strings', () => {
7474
const type = 'css'
7575
const selector = 'a[title="escaped"]'
76-
return expect(emit(`${type}=${selector}`)).resolves.toBe(
77-
'By.cssSelector("a[title=\\"escaped\\"]")'
78-
)
76+
return expect(emit(`${type}=${selector}`)).resolves.toMatchSnapshot()
7977
})
8078
it('should emit xpath locator', () => {
8179
const type = 'xpath'

packages/code-export-java-junit/src/command.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ async function emitEditContent(locator, content) {
396396
}
397397

398398
async function emitExecuteScript(script, varName) {
399-
const scriptString = script.script.replace(/"/g, "'")
400-
const result = `js.executeScript("${scriptString}"${generateScriptArguments(
399+
const result = `js.executeScript("${script.script}"${generateScriptArguments(
401400
script
402401
)})`
403402
return Promise.resolve(variableSetter(varName, result))

packages/code-export-javascript-mocha/__test__/src/__snapshots__/index.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ describe('login', function() {
2222
await driver.findElement(By.id(\\"username\\")).sendKeys(\\"tomsmith\\")
2323
await driver.findElement(By.id(\\"password\\")).sendKeys(\\"SuperSecretPassword!\\")
2424
await driver.findElement(By.css(\\"#login button\\")).click()
25-
assert(await driver.findElement(By.css(\\".flash.success\\")).getText() == \\"You logged into a secure area!\\\\\\\\\\")
25+
assert(await driver.findElement(By.css(\\".flash.success\\")).getText() == \\"You logged into a secure area!\\\\\\")
2626
})
2727
it('invalid credentials', async function() {
2828
await driver.get(\\"http://the-internet.herokuapp.com/login\\")
2929
await driver.setRect(1440, 1177)
3030
await driver.findElement(By.id(\\"username\\")).sendKeys(\\"blah\\")
3131
await driver.findElement(By.id(\\"password\\")).sendKeys(\\"blah\\")
3232
await driver.findElement(By.css(\\"#login button\\")).click()
33-
assert(await driver.findElement(By.id(\\"flash\\")).getText() == \\"Your username is invalid!\\\\\\\\\\")
33+
assert(await driver.findElement(By.id(\\"flash\\")).getText() == \\"Your username is invalid!\\\\\\")
3434
})
3535
})
3636
"
@@ -258,7 +258,7 @@ describe('login', function() {
258258
await driver.findElement(By.id(\\"username\\")).sendKeys(\\"tomsmith\\")
259259
await driver.findElement(By.id(\\"password\\")).sendKeys(\\"SuperSecretPassword!\\")
260260
await driver.findElement(By.css(\\"#login button\\")).click()
261-
assert(await driver.findElement(By.css(\\".flash.success\\")).getText() == \\"You logged into a secure area!\\\\\\\\\\")
261+
assert(await driver.findElement(By.css(\\".flash.success\\")).getText() == \\"You logged into a secure area!\\\\\\")
262262
})
263263
})
264264
"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`location code emitter should escape quotes in locator strings 1`] = `"By.css(\\"a[title=\\"escaped\\"]\\")"`;

packages/code-export-javascript-mocha/__test__/src/location.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ describe('location code emitter', () => {
7373
it('should escape quotes in locator strings', () => {
7474
const type = 'css'
7575
const selector = 'a[title="escaped"]'
76-
return expect(emit(`${type}=${selector}`)).resolves.toEqual(
77-
`By.css("a[title=\\"escaped\\"]")`
78-
)
76+
return expect(emit(`${type}=${selector}`)).resolves.toMatchSnapshot()
7977
})
8078
it('should emit xpath locator', () => {
8179
const type = 'xpath'

packages/code-export-javascript-mocha/src/command.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,9 @@ async function emitClose() {
249249
}
250250

251251
function generateExpressionScript(script) {
252-
const scriptString = script.script.replace(/"/g, "'")
253-
return `await driver.executeScript("return (${scriptString})"${generateScriptArguments(
254-
script
255-
)})`
252+
return `await driver.executeScript("return (${
253+
script.script
254+
})"${generateScriptArguments(script)})`
256255
}
257256

258257
function generateScriptArguments(script) {

packages/code-export-python-pytest/__test__/src/__snapshots__/index.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ class TestLogin():
2626
self.driver.find_element(By.ID, \\"username\\").send_keys(\\"tomsmith\\")
2727
self.driver.find_element(By.ID, \\"password\\").send_keys(\\"SuperSecretPassword!\\")
2828
self.driver.find_element(By.CSS_SELECTOR, \\"#login button\\").click()
29-
assert self.driver.find_element(By.CSS_SELECTOR, \\".flash.success\\").text == \\"You logged into a secure area!\\\\\\\\\\"
29+
assert self.driver.find_element(By.CSS_SELECTOR, \\".flash.success\\").text == \\"You logged into a secure area!\\\\\\"
3030
3131
def test_invalidcredentials(self):
3232
self.driver.get(\\"http://the-internet.herokuapp.com/login\\")
3333
self.driver.set_window_size(1440, 1177)
3434
self.driver.find_element(By.ID, \\"username\\").send_keys(\\"blah\\")
3535
self.driver.find_element(By.ID, \\"password\\").send_keys(\\"blah\\")
3636
self.driver.find_element(By.CSS_SELECTOR, \\"#login button\\").click()
37-
assert self.driver.find_element(By.ID, \\"flash\\").text == \\"Your username is invalid!\\\\\\\\\\"
37+
assert self.driver.find_element(By.ID, \\"flash\\").text == \\"Your username is invalid!\\\\\\"
3838
3939
"
4040
`;
@@ -268,7 +268,7 @@ class TestLogin():
268268
self.driver.find_element(By.ID, \\"username\\").send_keys(\\"tomsmith\\")
269269
self.driver.find_element(By.ID, \\"password\\").send_keys(\\"SuperSecretPassword!\\")
270270
self.driver.find_element(By.CSS_SELECTOR, \\"#login button\\").click()
271-
assert self.driver.find_element(By.CSS_SELECTOR, \\".flash.success\\").text == \\"You logged into a secure area!\\\\\\\\\\"
271+
assert self.driver.find_element(By.CSS_SELECTOR, \\".flash.success\\").text == \\"You logged into a secure area!\\\\\\"
272272
273273
"
274274
`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`location code emitter should escape quotes in locator strings 1`] = `"By.CSS_SELECTOR, \\"a[title=\\"escaped\\"]\\""`;

0 commit comments

Comments
 (0)