Skip to content

Commit

Permalink
Merge pull request #484 from qawolf/qawolf-web
Browse files Browse the repository at this point in the history
createplaywright -> qawolf
  • Loading branch information
jperl committed Mar 6, 2020
2 parents c64d101 + 949062f commit 31a8064
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/create-code/ContextEventCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BrowserContext } from 'playwright-core';
import { forEachPage, indexPages, initEvaluateScript } from 'playwright-utils';
import { IndexedPage } from 'playwright-utils/build/indexPages';
import { ElementEvent } from '../types';
import { CreatePlaywrightWeb } from '../web';
import { QAWolfWeb } from '../web';
import { addWebScript } from '../web/addScript';

const debug = Debug('qawolf:ContextEventCollector');
Expand Down Expand Up @@ -50,7 +50,7 @@ export class ContextEventCollector extends EventEmitter {
await initEvaluateScript(
page,
(attribute: string, pageIndex: number) => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;

new web.PageEventCollector({
attribute,
Expand Down
4 changes: 2 additions & 2 deletions src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import typescript from 'rollup-plugin-typescript';
export default {
input: './src/web/index.ts',
output: {
file: './build/createplaywright.web.js',
file: './build/qawolf.web.js',
format: 'iife',
name: 'createplaywright',
name: 'qawolf',
strict: false,
},
onwarn: (warning, next) => {
Expand Down
7 changes: 2 additions & 5 deletions src/web/addScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import { BrowserContext } from 'playwright-core';
import { forEachPage, initEvaluateScript } from 'playwright-utils';

export const WEB_SCRIPT = readFileSync(
join(__dirname.replace('/src', '/build'), '../createplaywright.web.js'),
join(__dirname.replace('/src', '/build'), '../qawolf.web.js'),
'utf8',
).replace(
'var createplaywright =',
'window.createplaywright = window.createplaywright ||',
);
).replace('var qawolf =', 'window.qawolf = window.qawolf ||');

export const addWebScript = async (context: BrowserContext): Promise<void> => {
await forEachPage(context, async page =>
Expand Down
4 changes: 2 additions & 2 deletions src/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PageEventCollector } from './PageEventCollector';
import { nodeToDoc, nodeToHtml, nodeToHtmlSelector } from './serialize';
import { getXpath } from './xpath';

const CreatePlaywrightWeb = {
const QAWolfWeb = {
buildCssSelector,
getAttributeValue,
getClickableAncestor,
Expand All @@ -22,4 +22,4 @@ const CreatePlaywrightWeb = {
nodeToHtmlSelector,
PageEventCollector,
};
export type CreatePlaywrightWeb = typeof CreatePlaywrightWeb;
export type QAWolfWeb = typeof QAWolfWeb;
6 changes: 3 additions & 3 deletions test/web/buildCssSelector.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Browser, Page } from 'playwright-core';
import { launch } from 'playwright-utils';
import { CreatePlaywrightWeb } from '../../src/web';
import { QAWolfWeb } from '../../src/web';
import { WEB_SCRIPT } from '../../src/web/addScript';
import {
AttributeValuePair,
Expand All @@ -18,7 +18,7 @@ const buildCssSelector = async (
): Promise<string | undefined> => {
const result = await page.evaluate(
(selector, isClick, attribute) => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const target = document.querySelector(selector) as HTMLElement;

return web.buildCssSelector({
Expand All @@ -41,7 +41,7 @@ const getAttributeValue = async (
): Promise<AttributeValuePair | null> => {
const result = await page.evaluate(
(selector, attribute) => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const button = document.querySelector(selector) as HTMLElement;
return web.getAttributeValue(button, attribute);
},
Expand Down
14 changes: 7 additions & 7 deletions test/web/element.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Browser, Page } from 'playwright-core';
import { launch } from 'playwright-utils';
import { CreatePlaywrightWeb } from '../../src/web';
import { QAWolfWeb } from '../../src/web';
import { WEB_SCRIPT } from '../../src/web/addScript';
import { TEST_URL } from '../utils';

Expand All @@ -19,7 +19,7 @@ afterAll(() => browser.close());
describe('getClickableAncestor', () => {
it('chooses the top most clickable ancestor', async () => {
const xpath = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const element = document.getElementsByTagName('p')[1];
if (!element) throw new Error('element not found');

Expand All @@ -32,7 +32,7 @@ describe('getClickableAncestor', () => {

it('chooses the original element when there is no clickable ancestor', async () => {
const xpath = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const element = document.getElementsByTagName('button')[0];
if (!element) throw new Error('element not found');

Expand All @@ -47,7 +47,7 @@ describe('getClickableAncestor', () => {
describe('isVisible', () => {
it('returns true if element is visible', async () => {
const isElementVisible = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const element = document.getElementById('username');
if (!element) throw new Error('element not found');

Expand All @@ -59,7 +59,7 @@ describe('isVisible', () => {

it('returns false if element has no width', async () => {
const isElementVisible = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const element = document.getElementById('username');
if (!element) throw new Error('element not found');

Expand All @@ -77,7 +77,7 @@ describe('isVisible', () => {
describe('isClickable', () => {
it('returns true if element is clickable', async () => {
const isClickable = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;

const loginButton = document.getElementsByTagName('button')[0];
return web.isClickable(loginButton, window.getComputedStyle(loginButton));
Expand All @@ -88,7 +88,7 @@ describe('isClickable', () => {

it('returns false if element is not clickable', async () => {
const isClickable = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const element = document.getElementById('username');
if (!element) throw new Error('element not found');

Expand Down
12 changes: 6 additions & 6 deletions test/web/serialize.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Browser, Page } from 'playwright-core';
import { launch } from 'playwright-utils';
import { CreatePlaywrightWeb } from '../../src/web';
import { QAWolfWeb } from '../../src/web';
import { WEB_SCRIPT } from '../../src/web/addScript';
import { TEST_URL } from '../utils';

Expand All @@ -19,7 +19,7 @@ afterAll(() => browser.close());
describe('nodeToDoc', () => {
it('serializes html and body elements by their tag only', async () => {
let doc = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const element = document.querySelector('html');
if (!element) throw new Error('element not found');
return web.nodeToDoc(element);
Expand All @@ -34,7 +34,7 @@ describe('nodeToDoc', () => {
});

doc = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const element = document.querySelector('body');
if (!element) throw new Error('element not found');
return web.nodeToDoc(element);
Expand All @@ -55,7 +55,7 @@ describe('nodeToHtml', () => {
await page.goto(`${TEST_URL}images`);

const html = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const element = document.querySelector('img');
if (!element) throw new Error('element not found');

Expand All @@ -69,7 +69,7 @@ describe('nodeToHtml', () => {
await page.goto(`${TEST_URL}login`);

const html = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;

const element = document.querySelector('input');
if (!element) throw new Error('element not found');
Expand All @@ -88,7 +88,7 @@ describe('nodeToHtmlSelector', () => {
await page.goto(`${TEST_URL}login`);

const html = await page.evaluate(() => {
const web: CreatePlaywrightWeb = (window as any).createplaywright;
const web: QAWolfWeb = (window as any).qawolf;
const element = document.querySelector('input');
if (!element) throw new Error('element not found');

Expand Down

0 comments on commit 31a8064

Please sign in to comment.