Skip to content

Commit

Permalink
fix: page context
Browse files Browse the repository at this point in the history
  • Loading branch information
jperl committed Aug 17, 2020
1 parent ef797cc commit 208089c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/build-code/buildStepLines.ts
Expand Up @@ -33,7 +33,10 @@ export const buildValue = ({ action, value }: Step): string => {
return JSON.stringify(value);
};

export const buildExpressionLine = (step: Step, frameVariable?: string): string => {
export const buildExpressionLine = (
step: Step,
frameVariable?: string,
): string => {
const { action, event } = step;

const args: string[] = [escapeSelector(event.selector)];
Expand All @@ -57,7 +60,7 @@ export const buildStepLines = (
buildContext: StepLineBuildContext = {
initializedFrames: new Map<string, string>(),
initializedPages: new Set(),
}
},
): string[] => {
const lines: string[] = [];

Expand All @@ -66,16 +69,24 @@ export const buildStepLines = (

const pageVariableName = getStepPageVariableName(step);
if (page > 0 && !initializedPages.has(page)) {
lines.push(`const ${pageVariableName} = await qawolf.waitForPage(context, ${page});`);
lines.push(
`const ${pageVariableName} = await qawolf.waitForPage(page.context(), ${page});`,
);
initializedPages.add(page);
}

let frameVariableName: string;
if (frameSelector) {
frameVariableName = initializedFrames.get(frameSelector);
if (!frameVariableName) {
frameVariableName = `frame${initializedFrames.size ? initializedFrames.size + 1 : ''}`;
lines.push(`const ${frameVariableName} = await (await ${pageVariableName}.$(${escapeSelector(frameSelector)})).contentFrame();`);
frameVariableName = `frame${
initializedFrames.size ? initializedFrames.size + 1 : ''
}`;
lines.push(
`const ${frameVariableName} = await (await ${pageVariableName}.$(${escapeSelector(
frameSelector,
)})).contentFrame();`,
);
initializedFrames.set(frameSelector, frameVariableName);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/build-code/buildStepLines.test.ts
Expand Up @@ -37,7 +37,7 @@ describe('buildStepLines', () => {

expect(lines).toMatchInlineSnapshot(`
Array [
"const page2 = await qawolf.waitForPage(context, 1);",
"const page2 = await qawolf.waitForPage(page.context(), 1);",
"await page2.click('[data-qa=\\"test-input\\"]');",
]
`);
Expand Down

0 comments on commit 208089c

Please sign in to comment.