Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/code-export-csharp-commons/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,16 @@ function emit(command: CommandShape, context: EmitterContext) {
context,
emitNewWindowHandling,
variableLookup,
variableInString,
})
}

// How a variable is joined with a string literal, e.g. "Hi " + name
const variableInString = {
quotes: ['"'],
toString: (lookup: string) => lookup,
}

function variableLookup(varName: string) {
return `vars["${varName}"].ToString()`
}
Expand Down Expand Up @@ -400,8 +407,7 @@ async function emitDragAndDrop(dragged: any, dropped: any) {
}

async function emitEcho(message: string) {
const _message = message.startsWith('vars[') ? message : `"${message}"`
return Promise.resolve(`Console.WriteLine(${_message});`)
return Promise.resolve(`Console.WriteLine("${message}");`)
}

async function emitEditContent(locator: any, content: any) {
Expand Down Expand Up @@ -645,9 +651,7 @@ function generateSendKeysInput(value: string | string[]) {
if (Array.isArray(value)) {
return value
.map((s) => {
if (s.startsWith('vars[')) {
return s
} else if (s.startsWith('Key[')) {
if (s.startsWith('Key[')) {
const key = (s.match(/\['(.*)'\]/) as RegExpMatchArray)[1]
return `Keys.${exporter.parsers.capitalize(key.toLowerCase())}`
} else {
Expand Down Expand Up @@ -1092,6 +1096,7 @@ async function emitWaitForElementNotVisible(locator: any, timeout: number) {
export default {
emitters,
variableLookup,
variableInString,
variableSetter,
emit,
register,
Expand Down
7 changes: 3 additions & 4 deletions packages/code-export-csharp-commons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.


import Command from './command'
import location from './location'

Expand All @@ -30,6 +29,6 @@ const exportFormat = {
},
} as const

export default exportFormat;
export {default as Command} from './command'
export {default as location} from './location'
export default exportFormat
export { default as Command } from './command'
export { default as location } from './location'
2 changes: 1 addition & 1 deletion packages/code-export-csharp-nunit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ export const opts: LanguageEmitterOpts = {
}

// Emit an individual test, wrapped in a suite (using the test name as the suite name)
export default languageFromOpts(opts, location.emit);
export default languageFromOpts(opts, location.emit)
1 change: 1 addition & 0 deletions packages/code-export-csharp-xunit/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function emit(command: CommandShape, context: EmitterContext) {
context,
emitNewWindowHandling: Command.extras.emitNewWindowHandling,
variableLookup: Command.variableLookup,
variableInString: Command.variableInString,
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/code-export-csharp-xunit/src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const emitters = {
inEachEnd: empty,
} as const

export default emitters;
export default emitters

function beforeEach() {
const params: HookFunctionInputs = {
Expand Down
14 changes: 9 additions & 5 deletions packages/code-export-java-junit/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ function emit(command: CommandShape, context: EmitterContext) {
return exporter.emit.command(command, emitters[command.command], {
context,
variableLookup,
variableInString,
emitNewWindowHandling,
})
}

// How a variable is joined with a string literal, e.g. "Hi " + name
const variableInString = {
quotes: ['"'],
toString: (lookup: string) => lookup,
}

function variableLookup(varName: string) {
return `vars.get("${varName}").toString()`
}
Expand Down Expand Up @@ -389,8 +396,7 @@ async function emitDragAndDrop(dragged: string, dropped: string) {
}

async function emitEcho(message: string) {
const _message = message.startsWith('vars.get') ? message : `"${message}"`
return Promise.resolve(`System.out.println(${_message});`)
return Promise.resolve(`System.out.println("${message}");`)
}

async function emitEditContent(locator: string, content: string) {
Expand Down Expand Up @@ -632,9 +638,7 @@ function generateSendKeysInput(value: string | string[]) {
if (typeof value === 'object') {
return value
.map((s) => {
if (s.startsWith('vars.get')) {
return s
} else if (s.startsWith('Key[')) {
if (s.startsWith('Key[')) {
const key = s.match(/\['(.*)'\]/)?.[1] as string
return `Keys.${key}`
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/code-export-java-junit/src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

import { HookFunctionInputs } from "side-code-export"
import { HookFunctionInputs } from 'side-code-export'

const emitters = {
afterAll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ exports[`command code emitter should emit \`drag and drop to object\` command 1`

exports[`command code emitter should emit \`echo\` command 1`] = `"console.log(\\"blah\\")"`;

exports[`command code emitter should emit \`echo\` command with variables 1`] = `"console.log(vars[\\"blah\\"])"`;
exports[`command code emitter should emit \`echo\` command with variables 1`] = `"console.log(String(vars[\\"blah\\"]))"`;

exports[`command code emitter should emit \`edit content\` command 1`] = `
"{
Expand Down Expand Up @@ -299,7 +299,7 @@ exports[`command code emitter should emit \`send keys\` command 1`] = `"await dr

exports[`command code emitter should emit \`send keys\` command with a key press 1`] = `"await driver.findElement(By.id(\\"input\\")).sendKeys(\\"SuperSecretPassword!\\", Key.ENTER)"`;

exports[`command code emitter should emit \`send keys\` command with a variable input 1`] = `"await driver.findElement(By.id(\\"input\\")).sendKeys(vars[\\"blah\\"])"`;
exports[`command code emitter should emit \`send keys\` command with a variable input 1`] = `"await driver.findElement(By.id(\\"input\\")).sendKeys(String(vars[\\"blah\\"]))"`;

exports[`command code emitter should emit \`set speed\` 1`] = `"console.log(\\"\`set speed\` is a no-op in code export, use \`pause\` instead\\")"`;

Expand Down
14 changes: 9 additions & 5 deletions packages/code-export-javascript-mocha/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ function emit(command: CommandShape, context: EmitterContext) {
return exporter.emit.command(command, emitters[command.command], {
context,
variableLookup,
variableInString,
emitNewWindowHandling,
})
}

// How a variable is joined with a string literal, e.g. "Hi " + name
const variableInString = {
quotes: ['"', "'", '`'],
toString: (lookup: string) => `String(${lookup})`,
}
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved

function variableLookup(varName: string) {
return `vars["${varName}"]`
}
Expand Down Expand Up @@ -417,8 +424,7 @@ async function emitDragAndDrop(dragged: string, dropped: string) {
}

async function emitEcho(message: string) {
const _message = message.startsWith('vars[') ? message : `"${message}"`
return Promise.resolve(`console.log(${_message})`)
return Promise.resolve(`console.log("${message}")`)
}

async function emitEditContent(locator: string, content: string) {
Expand Down Expand Up @@ -647,9 +653,7 @@ function generateSendKeysInput(value: string | string[]) {
if (typeof value === 'object') {
return value
.map((s) => {
if (s.startsWith('vars[')) {
return s
} else if (s.startsWith('Key[')) {
if (s.startsWith('Key[')) {
const key = s.match(/\['(.*)'\]/)?.[1]
return `Key.${key}`
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/code-export-javascript-mocha/src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the specific language governing permissions and limitations
// under the License.

import { HookFunctionInputs } from "side-code-export"
import { HookFunctionInputs } from 'side-code-export'

const emitters = {
afterAll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ actions.drag_and_drop(dragged, dropped).perform()"

exports[`command code emitter should emit \`echo\` command 1`] = `"print(\\"blah\\")"`;

exports[`command code emitter should emit \`echo\` command with variables 1`] = `"print(\\"blah = {}\\".format(self.vars[\\"blah\\"]))"`;
exports[`command code emitter should emit \`echo\` command with variables 1`] = `"print(\\"blah = \\" + str(self.vars[\\"blah\\"]))"`;

exports[`command code emitter should emit \`edit content\` command 1`] = `
"element = self.driver.find_element(By.ID, \\"contentEditable\\")
Expand Down Expand Up @@ -257,7 +257,7 @@ exports[`command code emitter should emit \`send keys\` command 1`] = `"self.dri

exports[`command code emitter should emit \`send keys\` command with a key press 1`] = `"self.driver.find_element(By.ID, \\"input\\").send_keys(\\"SuperSecretPassword!\\", Keys.ENTER)"`;

exports[`command code emitter should emit \`send keys\` command with a variable input 1`] = `"self.driver.find_element(By.ID, \\"input\\").send_keys(self.vars[\\"blah\\"])"`;
exports[`command code emitter should emit \`send keys\` command with a variable input 1`] = `"self.driver.find_element(By.ID, \\"input\\").send_keys(str(self.vars[\\"blah\\"]))"`;

exports[`command code emitter should emit \`set speed\` 1`] = `"print(\\"\`set speed\` is a no-op in code export, use \`pause\` instead\\")"`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

import { defaultPreprocessor, resolveVariables } from 'side-code-export'
import { emit } from '../../src/selection'

describe('selection location code emitter', () => {
Expand All @@ -35,12 +36,14 @@ describe('selection location code emitter', () => {
`By.XPATH, "//option[. = '${selector}']"`
)
})
it('should emit label locator with variable', () => {
const type = 'label'
const selector = 'self.vars["label"]'
return expect(emit(`${type}=${selector}`)).resolves.toEqual(
`By.XPATH, "//option[. = '{}']".format(${selector})`
)
it('should emit label locator with variable', async () => {
const code = await emit(defaultPreprocessor('label=${label}'))
expect(
resolveVariables(code, (name) => `self.vars["${name}"]`, {
quotes: ['"', "'"],
toString: (lookup) => `str(${lookup})`,
})
).toEqual(`By.XPATH, "//option[. = '" + str(self.vars["label"]) + "']"`)
})
it('should emit id locator', () => {
const type = 'id'
Expand Down
26 changes: 9 additions & 17 deletions packages/code-export-python-pytest/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ function emit(command: CommandShape, context: EmitterContext) {
return exporter.emit.command(command, emitters[command.command], {
context,
variableLookup,
variableInString,
emitNewWindowHandling,
})
}

// How a variable is joined with a string literal, e.g. "Hi " + name
const variableInString = {
quotes: ['"', "'"],
toString: (lookup: string) => `str(${lookup})`,
}

function variableLookup(varName: string) {
return `self.vars["${varName}"]`
}
Expand Down Expand Up @@ -394,21 +401,8 @@ async function emitDragAndDrop(dragged: string, dropped: string) {
return Promise.resolve({ commands })
}

function translateToPythonString(str: string) {
const regExp = /self.vars\["\w+"]/
const vars = str.match(regExp)

if (vars && vars.length > 0) {
const fmtStr = str.replace(regExp, '{}')
return `"${fmtStr}".format(${vars.join(', ')})`
}

return `"${str}"`
}

async function emitEcho(message: string) {
const _message = translateToPythonString(message)
return Promise.resolve(`print(${_message})`)
return Promise.resolve(`print("${message}")`)
}

async function emitEditContent(locator: string, content: string) {
Expand Down Expand Up @@ -616,9 +610,7 @@ function generateSendKeysInput(value: string | string[]) {
if (typeof value === 'object') {
return value
.map((s) => {
if (s.startsWith('self.vars[')) {
return s
} else if (s.startsWith('Key[')) {
if (s.startsWith('Key[')) {
const key = s.match(/\['(.*)'\]/)?.[1]
return `Keys.${key}`
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/code-export-python-pytest/src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the specific language governing permissions and limitations
// under the License.

import { HookFunctionInputs } from "side-code-export"
import { HookFunctionInputs } from 'side-code-export'

const emitters = {
afterAll,
Expand Down
3 changes: 0 additions & 3 deletions packages/code-export-python-pytest/src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ function emitValue(value: string) {
}

function emitLabel(label: string) {
if (label.startsWith('self.vars[')) {
return Promise.resolve(`By.XPATH, "//option[. = '{}']".format(${label})`)
}
return Promise.resolve(`By.XPATH, "//option[. = '${label}']"`)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ dropped = @driver.find_element(:link_text, 'dropped')

exports[`command code emitter should emit \`echo\` command 1`] = `"puts('blah')"`;

exports[`command code emitter should emit \`echo\` command with variables 1`] = `"puts(@vars['blah'])"`;
exports[`command code emitter should emit \`echo\` command with variables 1`] = `"puts(@vars['blah'].to_s)"`;

exports[`command code emitter should emit \`edit content\` command 1`] = `
"element = @driver.find_element(:id, 'contentEditable')
Expand Down Expand Up @@ -249,7 +249,7 @@ exports[`command code emitter should emit \`send keys\` command 1`] = `"@driver.

exports[`command code emitter should emit \`send keys\` command with a key press 1`] = `"@driver.find_element(:id, 'input').send_keys('SuperSecretPassword!', :enter)"`;

exports[`command code emitter should emit \`send keys\` command with a variable input 1`] = `"@driver.find_element(:id, 'input').send_keys(@vars['blah'])"`;
exports[`command code emitter should emit \`send keys\` command with a variable input 1`] = `"@driver.find_element(:id, 'input').send_keys(@vars['blah'].to_s)"`;

exports[`command code emitter should emit \`set speed\` 1`] = `"print(\\"\`set speed\` is a no-op in code export, use \`pause\` instead\\")"`;

Expand Down
14 changes: 9 additions & 5 deletions packages/code-export-ruby-rspec/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,17 @@ function emit(command: CommandShape, context: EmitterContext) {
return exporter.emit.command(command, emitters[command.command], {
context,
variableLookup,
variableInString,
emitNewWindowHandling,
})
}

// How a variable is joined with a string literal, e.g. "Hi " + name
const variableInString = {
quotes: ['"', "'"],
toString: (lookup: string) => `${lookup}.to_s`,
}

function variableLookup(varName: string) {
return `@vars['${varName}']`
}
Expand Down Expand Up @@ -387,8 +394,7 @@ async function emitDragAndDrop(dragged: string, dropped: string) {
}

async function emitEcho(message: string) {
const _message = message.startsWith('@vars[') ? message : `'${message}'`
return Promise.resolve(`puts(${_message})`)
return Promise.resolve(`puts('${message}')`)
}

async function emitEditContent(locator: string, content: string) {
Expand Down Expand Up @@ -592,9 +598,7 @@ function generateSendKeysInput(value: string | string[]) {
if (typeof value === 'object') {
return value
.map((s) => {
if (s.startsWith('@vars[')) {
return s
} else if (s.startsWith('Key[')) {
if (s.startsWith('Key[')) {
const key = s.match(/\['(.*)'\]/)?.[1]
return `:${key?.toLowerCase()}`
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/code-export-ruby-rspec/src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the specific language governing permissions and limitations
// under the License.

import { HookFunctionInputs } from "side-code-export";
import { HookFunctionInputs } from 'side-code-export'

const emitters = {
afterAll,
Expand All @@ -28,7 +28,7 @@ const emitters = {
inEachEnd: empty,
}

export default emitters;
export default emitters

function afterAll() {
const params = {
Expand Down
Loading
Loading