Skip to content

Commit

Permalink
Handle case where device specified
Browse files Browse the repository at this point in the history
  • Loading branch information
flaurida committed Mar 26, 2020
1 parent 41dc8f9 commit da89307
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/build-code/buildTemplate.ts
Expand Up @@ -45,15 +45,17 @@ export const buildImports = ({

if (device) {
if (useTypeScript) {
imports += 'import { devices } from "playwright";\n';
imports += 'import { Browser, Page, devices } from "playwright";\n';
} else {
imports += 'const { devices } = require("playwright");\n';
}
}

if (useTypeScript) {
if (useTypeScript && !device) {
imports +=
'import { Browser, Page } from "playwright";\nimport qawolf from "qawolf";\n';
} else if (useTypeScript) {
imports += 'import qawolf from "qawolf";\n';
} else {
imports += 'const qawolf = require("qawolf");\n';
}
Expand Down
56 changes: 54 additions & 2 deletions test/build-code/__snapshots__/buildTemplate.test.ts.snap
Expand Up @@ -7,8 +7,7 @@ const selectors = require(\\"./selectors/myScript.json\\");"
`;

exports[`buildImports imports when typescript 2`] = `
"import { devices } from \\"playwright\\";
import { Browser, Page } from \\"playwright\\";
"import { Browser, Page, devices } from \\"playwright\\";
import qawolf from \\"qawolf\\";
const selectors = require(\\"./selectors/myScript.json\\");
const device = devices[\\"iPhone 11\\"];"
Expand Down Expand Up @@ -178,3 +177,56 @@ test('myName', async () => {
await qawolf.create();
});"
`;

exports[`buildTemplate builds test template 4`] = `
"import { Browser, Page } from \\"playwright\\";
import qawolf from \\"qawolf\\";
const selectors = require(\\"./selectors/myName.json\\");
let browser: Browser;
let page: Page;
beforeAll(async () => {
browser = await qawolf.launch();
const context = await browser.newContext();
await qawolf.register(context);
page = await context.newPage();
});
afterAll(async () => {
await qawolf.stopVideos();
await browser.close();
});
test('myName', async () => {
await page.goto(\\"www.qawolf.com\\");
await qawolf.create();
});"
`;

exports[`buildTemplate builds test template 5`] = `
"import { Browser, Page, devices } from \\"playwright\\";
import qawolf from \\"qawolf\\";
const selectors = require(\\"./selectors/myName.json\\");
const device = devices[\\"iPhone 7\\"];
let browser: Browser;
let page: Page;
beforeAll(async () => {
browser = await qawolf.launch();
const context = await browser.newContext({ ...device });
await qawolf.register(context);
page = await context.newPage();
});
afterAll(async () => {
await qawolf.stopVideos();
await browser.close();
});
test('myName', async () => {
await page.goto(\\"www.qawolf.com\\");
await qawolf.create();
});"
`;
13 changes: 13 additions & 0 deletions test/build-code/buildTemplate.test.ts
Expand Up @@ -88,6 +88,19 @@ describe('buildTemplate', () => {
statePath: 'admin.json',
});
expect(template).toMatchSnapshot();

template = buildTemplate({
...options,
useTypeScript: true,
});
expect(template).toMatchSnapshot();

template = buildTemplate({
...options,
useTypeScript: true,
device: 'iPhone 7',
});
expect(template).toMatchSnapshot();
});
});

Expand Down

0 comments on commit da89307

Please sign in to comment.