Skip to content

Commit

Permalink
feat: example test (#364)
Browse files Browse the repository at this point in the history
* feat: example test

* feat: added action workflow
  • Loading branch information
jinwoo-kim-nhn committed Mar 20, 2020
1 parent 5369a4a commit 3608146
Show file tree
Hide file tree
Showing 4 changed files with 483 additions and 139 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/examplePageTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

name: Node.js CI

on:
schedule:
- cron: '0 14,22 * * *'
push:
branches: [ feat/examplePageTest ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: ROWSERSTACK_ACCESS_KEY=$BROWSERSTACK_ACCESS_KEY
- run: BROWSERSTACK_USERNAME=$BROWSERSTACK_USERNAME
- run: node exampleTest.js
env:
CI: true
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
121 changes: 121 additions & 0 deletions exampleTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
const BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME;
const BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY;
const assert = require('assert');
const http = require('http');
const {Builder} = require('selenium-webdriver');

const HttpAgent = new http.Agent({
keepAlive: true
});

const urlpreset = 'http:https://nhn.github.io/tui.image-editor/latest';
const testUrls = [
'/examples/example01-includeUi.html',
'/examples/example02-useApiDirect.html'
];

const capabilities = [
{
browserName: 'Firefox',
name: 'Firefox Test',
os: 'Windows'
}, {
browserName: 'Chrome',
name: 'Chrome Test',
os: 'Windows'
}, {
os: 'Windows',
osVersion: '7',
name: 'IE10 Test',
browserName: 'IE',
browserVersion: '10.0'
}, {
os: 'Windows',
osVersion: '10',
name: 'IE11 Test',
browserName: 'IE',
browserVersion: '11.0'
}, {
os: 'OS X',
osVersion: 'Catalina',
name: 'Safari Test',
browserName: 'Safari'
}, {
os: 'Windows',
osVersion: '10',
name: 'Edge Test',
browserName: 'Edge'
}
];

if (!BROWSERSTACK_USERNAME || !BROWSERSTACK_ACCESS_KEY) {
throw Error('Id password required');
}

testAllUrl(testUrls);

async function testAllUrl(urls) {
let errorCount = 0;

for(let i = 0; i <= urls.length - 1; i++) {
const url = urlpreset + urls[i];
const errorBrowsersInfo = await testOneUrl(url);

errorCount += errorBrowsersInfo.length;
printErrorLog(url, errorBrowsersInfo);
}

assert.equal(errorCount, 0);
}

async function testOneUrl(url) {
const parallelPendingTests = Object.keys(capabilities).map(index => testAllPlatform(index, url));
const testResults = await Promise.all(parallelPendingTests);
return testResults.reduce((errorList, errorInfo) => {
if (!errorInfo.errorLogs) {
errorInfo.errorLogs = {message: 'Not exist error catch code snippet in example page'};
errorList.push(errorInfo);
} else if (errorInfo.errorLogs.length) {
errorList.push(errorInfo);
}
return errorList;
}, []);
}

async function testAllPlatform(index, url) {
const driver = getDriver(index);

await driver.get(url);
await driver.wait(function() {
return driver.executeScript('return document.readyState').then(function(readyState) {
return readyState === 'complete';
});
}, 20000);

const browserInfo = await driver.getCapabilities();
const errorLogs = await driver.executeScript('return window.errorLogs');

driver.quit();

return {
browserName: browserInfo.get("browserName"),
browserVersion: browserInfo.get("version") || browserInfo.get("browserVersion"),
errorLogs
};
}

function getDriver(index) {
return new Builder()
.usingHttpAgent(HttpAgent)
.withCapabilities(Object.assign({}, capabilities[index], {build: `examplePageTest-${new Date().toLocaleDateString()}`}))
.usingServer(`http:https://${BROWSERSTACK_USERNAME}:${BROWSERSTACK_ACCESS_KEY}@hub.browserstack.com/wd/hub`)
.build();
}

function printErrorLog(url, errorBrowsersInfo) {
console.log(url);
errorBrowsersInfo.forEach(errorInfo => {
console.log(errorInfo.browserName, errorInfo.browserVersion, errorInfo.errorLogs);
});
}

Loading

0 comments on commit 3608146

Please sign in to comment.