Skip to content

Commit

Permalink
Fixed e2e tests, implemented basic puppeteer methods
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthecat committed Sep 28, 2018
1 parent 45ee0ce commit c7149cc
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 106 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,28 @@
]
},
"devDependencies": {
"@types/chai": "4.1.4",
"@types/chai": "4.1.5",
"@types/mocha": "5.2.5",
"@types/node": "10.5.6",
"babel-eslint": "8.2.6",
"chai": "4.1.2",
"@types/node": "10.11.2",
"babel-eslint": "10.0.1",
"chai": "4.2.0",
"coveralls": "3.0.2",
"eslint": "5.3.0",
"eslint": "5.6.0",
"eslint-config-ringcentral": "0.3.0",
"eslint-plugin-react": "7.9.1",
"eslint-plugin-react": "7.11.1",
"eslint-plugin-typescript": "0.12.0",
"fs-extra": "7.0.0",
"glob": "7.1.2",
"glob": "7.1.3",
"lerna": "2.11.0",
"mocha": "5.2.0",
"npm-check": "5.8.0",
"npm-check": "5.9.0",
"npm-utils": "2.0.3",
"nyc": "12.0.2",
"nyc": "13.0.1",
"pre-commit": "1.2.2",
"rimraf": "2.6.2",
"sinon": "6.1.4",
"ts-node": "7.0.0",
"typescript": "3.0.1",
"typescript-eslint-parser": "17.0.1"
"sinon": "6.3.4",
"ts-node": "7.0.1",
"typescript": "3.1.1",
"typescript-eslint-parser": "19.0.1"
}
}
10 changes: 9 additions & 1 deletion packages/api/src/test-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ const LOG_PREFIX = '[logged inside test]';

export class TestContext {

private _application: WebApplication;

private lastLoggedBusinessMessage: string | null = null;

private customApplications: Set<WebApplication> = new Set();

public http = new HttpClient(transport);

public get application() {
if (this._application) {
return this._application;
}

const runData = this.getRunData();

return new WebApplication(testAPIController.getTestID(), transport, runData);
this._application = new WebApplication(testAPIController.getTestID(), transport, runData);

return this._application;
}

public async logBusiness(message: string) {
Expand Down
6 changes: 3 additions & 3 deletions packages/browser-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"@testring/types": "0.4.29",
"@testring/utils": "0.4.29",
"@types/nanoid": "^1.2.0",
"@types/yargs": "^11.0.0",
"nanoid": "^1.2.3",
"yargs": "^12.0.1"
"@types/yargs": "^12.0.0",
"nanoid": "^1.2.4",
"yargs": "^12.0.2"
},
"devDependencies": {
"@testring/test-utils": "0.4.29"
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"@testring/types": "0.4.29",
"@testring/utils": "0.4.29",
"@types/deepmerge": "^2.1.0",
"@types/yargs": "^11.0.0",
"@types/yargs": "^12.0.0",
"deepmerge": "^2.1.1",
"yargs": "^12.0.1"
"yargs": "^12.0.2"
}
}
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@testring/transport": "0.4.29",
"@testring/types": "0.4.29",
"@testring/web-application": "0.4.29",
"@types/yargs": "^11.0.0",
"yargs": "^12.0.1"
"@types/yargs": "^12.0.0",
"yargs": "^12.0.2"
}
}
2 changes: 1 addition & 1 deletion packages/e2e-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test:simple-run": "testring run --config test/simple/.testringrc --env-parameters.test 10 --rc.tags-list=#P0,#P1",
"test:run-and-record": "testring record --config test/simple/config.json --tests test/simple/*.spec.js",
"e2e-simple": "npm run test:simple-run",
"e2e": "npm run test:simple-run && npm run test:puppeteer"
"e2e": "npm run test:simple-run && npm run test:selenium && npm run test:puppeteer"
},
"dependencies": {
"@testring/plugin-babel": "0.4.29",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = async () => ({
workerLimit: 5,
retryCount: 0,
tests: 'test/proxy-plugins/test/get-text.spec.js',
tests: 'test/proxy-plugins/test/*.spec.js',
plugins: [
'puppeteer',
['babel', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ run(async (api) => {

await api.logBusiness('redirecting');

await api.application.click(
api.application.root.credential
);

await api.application.keys('1111111111');
await api.application.setValue(api.application.root.credential.input, '1111111111');

await api.application.click(
api.application.root.loginCredentialNext
Expand Down
8 changes: 2 additions & 6 deletions packages/e2e-test-app/test/proxy-plugins/test/keys.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import { run } from 'testring';
run(async (api) => {
await api.application.url('https://service.ringcentral.com/');

await api.application.click(
api.application.root.credential.input
);

await api.application.keys('testRing');
await api.application.setValue(api.application.root.credential.input, 'testRing');

const credentialValue = await api.application.getValue(
api.application.root.credential
api.application.root.credential.input
);

await api.application.assert.equal(credentialValue, 'testRing');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { run } from 'testring';

run(async (api) => {

await api.application.url('https://service.ringcentral.com/');
await api.application.setValue(api.application.root.credential.input, '1111111111');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { run } from 'testring';

run(async (api) => {
await api.application.openPage('https://service.ringcentral.com/');
await api.application.url('https://service.ringcentral.com/');
});
2 changes: 1 addition & 1 deletion packages/fs-reader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"@testring/logger": "0.4.29",
"@testring/pluggable-module": "0.4.29",
"@testring/types": "0.4.29",
"glob": "^7.1.2"
"glob": "^7.1.3"
}
}
2 changes: 1 addition & 1 deletion packages/http-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/nanoid": "^1.2.0",
"@types/request-promise": "^4.1.42",
"@types/tough-cookie": "^2.3.3",
"nanoid": "^1.2.3",
"nanoid": "^1.2.4",
"request-promise": "^4.2.2",
"tough-cookie": "^2.4.3"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/nanoid": "^1.2.0",
"bytes": "^3.0.0",
"chalk": "^2.4.1",
"nanoid": "^1.2.3"
"nanoid": "^1.2.4"
},
"devDependencies": {
"@testring/test-utils": "0.4.29"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"@types/puppeteer": "1.6.4",
"@types/nanoid": "^1.2.0",
"puppeteer": "1.8.0",
"nanoid": "^1.2.3"
"nanoid": "^1.2.4"
}
}
6 changes: 1 addition & 5 deletions packages/plugin-puppeteer/src/plugin/browser-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ export class BrowserInstance {
private pages: Map<PageID, Page> = new Map();

constructor(options: LaunchOptions) {
this.initialPromise = new Promise(async (resolve) => {
await this.createBrowserAPI(options);

setTimeout(resolve, 100);
});
this.initialPromise = this.createBrowserAPI(options);
}

public waitForInit() {
Expand Down
74 changes: 58 additions & 16 deletions packages/plugin-puppeteer/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IBrowserProxyPlugin } from '@testring/types';
import { BrowserInstance } from './browser-instance';

const DEFAULT_CONFIG: LaunchOptions = {
headless: false,
headless: true,
};

function delay(timeout) {
Expand All @@ -21,6 +21,8 @@ export class PuppeteerPlugin implements IBrowserProxyPlugin {
const currentBrowserInstance = this.browserClients.get(applicant);

if (currentBrowserInstance) {
await currentBrowserInstance.waitForInit();

return currentBrowserInstance;
}

Expand Down Expand Up @@ -69,7 +71,14 @@ export class PuppeteerPlugin implements IBrowserProxyPlugin {

if (browserInstance) {
const client = await browserInstance.getCurrentContext();
return client.click(selector);

await client.waitForXPath(selector);

const elements = await client.$x(selector);

if (elements.length) {
await elements[0].click();
}
}
}

Expand All @@ -87,7 +96,8 @@ export class PuppeteerPlugin implements IBrowserProxyPlugin {

if (browserInstance) {
const client = await browserInstance.getCurrentContext();
return client.waitForXPath(xpath, { timeout });

return !!client.waitForXPath(xpath, { timeout });
}
}

Expand All @@ -96,7 +106,8 @@ export class PuppeteerPlugin implements IBrowserProxyPlugin {

if (browserInstance) {
const client = await browserInstance.getCurrentContext();
return client.waitForXPath(xpath, { timeout, visible: true });

return !!client.waitForXPath(xpath, { timeout, visible: true });
}
}

Expand Down Expand Up @@ -198,28 +209,37 @@ export class PuppeteerPlugin implements IBrowserProxyPlugin {
}
}

public async getValue(applicant: string, xpath: string) {
public async getValue(applicant: string, selector: string) {
const browserInstance = await this.createClient(applicant);

if (browserInstance) {
const client = await browserInstance.getCurrentContext();
return client.$eval(xpath, (node: any) => node.value);

await client.waitForXPath(selector);

const elements = await client.$x(selector);

if (elements.length) {
return await client.evaluate((node) => node.value, elements[0]);
}

return null;
}
}

public async setValue(applicant: string, xpath: string, value: any) {
public async setValue(applicant: string, selector: string, value: any) {
const browserInstance = await this.createClient(applicant);

if (browserInstance) {
const client = await browserInstance.getCurrentContext();

const elements = await client.$x(xpath);
await client.waitForXPath(selector);

if (elements[0]) {
elements[0].type(value);
}
const elements = await client.$x(selector);

return client.type(xpath, value);
if (elements.length) {
await elements[0].type(value);
}
}
}

Expand Down Expand Up @@ -250,14 +270,25 @@ export class PuppeteerPlugin implements IBrowserProxyPlugin {
}
}

public async getAttribute(applicant: string, xpath: string, attr: string): Promise<any> {
public async getAttribute(applicant: string, selector: string, attr: string): Promise<any> {
const browserInstance = await this.createClient(applicant);

if (browserInstance) {
const client = await browserInstance.getCurrentContext();
const attributes = await client.$eval(xpath, (node) => node.attributes);

return attributes[attr];
await client.waitForXPath(selector);

const elements = await client.$x(selector);

if (elements.length) {
return await client.evaluate(
(node, attr) => node.getAttribute(attr),
elements[0],
attr,
);
}

return null;
}
}

Expand Down Expand Up @@ -429,7 +460,18 @@ export class PuppeteerPlugin implements IBrowserProxyPlugin {

if (browserInstance) {
const client = await browserInstance.getCurrentContext();
return client.$eval(xpath, (node) => node.textContent);

await client.waitForXPath(xpath);

const element = await client.$x(xpath);

if (element.length) {
const textContent = await element[0].getProperty('textContent');

return await textContent.jsonValue();
}

return '';
}
}

Expand Down
14 changes: 7 additions & 7 deletions packages/recorder-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
"@types/koa": "^2.0.46",
"@types/koa-static": "^4.0.0",
"@types/koa-views": "^2.0.3",
"@types/ws": "^5.1.2",
"@types/ws": "^6.0.1",
"babel-traverse": "^6.26.0",
"babel-types": "^6.26.0",
"chrome-launcher": "^0.10.2",
"koa": "^2.5.2",
"chrome-launcher": "^0.10.5",
"koa": "^2.5.3",
"koa-static": "^5.0.0",
"koa-views": "^6.1.4",
"nanoid": "^1.2.3",
"nanoid": "^1.2.4",
"ws": "^6.0.0"
},
"devDependencies": {
"@testring/test-utils": "0.4.29",
"@testring/utils": "0.4.29",
"nodemon": "^1.17.5",
"request": "2.87.0",
"nodemon": "1.18.4",
"request": "2.88.0",
"request-promise": "4.2.2",
"ts-node": "7.0.0"
"ts-node": "7.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/recorder-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@types/chrome": "0.0.69",
"@types/webpack": "4.4.5",
"mkdirp": "^0.5.1",
"nanoid": "^1.2.3",
"nanoid": "^1.2.4",
"ncp": "^2.0.0",
"nodemon": "^1.18.1",
"ts-loader": "^4.4.2",
Expand Down

0 comments on commit c7149cc

Please sign in to comment.