Skip to content

Commit

Permalink
Merge b7dd0c4 into 0f6882d
Browse files Browse the repository at this point in the history
  • Loading branch information
ByMsx committed Dec 19, 2019
2 parents 0f6882d + b7dd0c4 commit c1ee230
Show file tree
Hide file tree
Showing 34 changed files with 568 additions and 145 deletions.
28 changes: 28 additions & 0 deletions packages/e2e-test-app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as childProcess from 'child_process';
import { MockWebServer } from './src/mock-web-server';

const mockWebServer = new MockWebServer();
mockWebServer.start();

const testringProcess = childProcess.exec(
'./node_modules/.bin/testring run --config ./test/selenium/config.js',
{},
(error, stdout, stderr) => {
mockWebServer.stop();

if (error) {
throw error;
}
});

if (testringProcess.stdout) {
testringProcess.stdout.pipe(process.stdout);
} else {
console.warn('Cannot pipe stdout of child process');
}

if (testringProcess.stderr) {
testringProcess.stderr.pipe(process.stderr);
} else {
console.warn('Cannot pipe stderr of child process');
}
6 changes: 5 additions & 1 deletion packages/e2e-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
"author": "RingCentral",
"license": "MIT",
"scripts": {
"test:selenium": "testring run --config ./test/selenium/config.js",
"test:selenium": "ts-node index.ts",
"test:simple-run": "testring run --config test/simple/.testringrc --env-parameters.test 10 --rc.tags-list=#P0,#P1",
"test:run-with-devtool": "testring run --config ./test/selenium/config.js --devtool",
"e2e-simple": "npm run test:simple-run",
"e2e": "npm run test:simple-run && npm run test:selenium"
},
"dependencies": {
"@testring/cli": "0.5.14",
"@testring/plugin-babel": "0.5.14",
"@testring/plugin-selenium-driver": "0.5.14",
"@testring/web-application": "0.5.14",
"@types/express": "4.17.2",
"babel-preset-es2015": "6.24.1",
"express": "4.17.1",
"testring": "0.5.14"
}
}
20 changes: 20 additions & 0 deletions packages/e2e-test-app/src/mock-web-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as express from 'express';
import * as Http from 'http';

export class MockWebServer {
private httpServerInstance: Http.Server;

start() {
this.httpServerInstance = MockWebServer.createExpressWebApplication().listen(8080);
}

stop() {
this.httpServerInstance.close();
}

private static createExpressWebApplication(): express.Application {
const app = express();
app.use(express.static('static-fixtures'));
return app;
}
}
24 changes: 24 additions & 0 deletions packages/e2e-test-app/static-fixtures/alert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body data-test-automation-id="root">
<div data-test-automation-id="alerts">
<p data-test-automation-id="first" class="alerts"></p>
<p data-test-automation-id="second" class="alerts"></p>
<p data-test-automation-id="third" class="alerts"></p>
</div>
<script>
const a1 = confirm();
document.getElementsByClassName('alerts')[0].innerText = a1;

const a2 = confirm();
document.getElementsByClassName('alerts')[1].innerText = a2;

const a3 = confirm('test');
document.getElementsByClassName('alerts')[2].innerText = a3;
</script>
</body>
</html>
16 changes: 16 additions & 0 deletions packages/e2e-test-app/static-fixtures/click.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function test() {
document.getElementById('output').innerText = 'test';
}
</script>
</head>
<body data-test-automation-id="root">
<button data-test-automation-id="button" onclick="test()">Press me!</button>
<p id="output" data-test-automation-id="output"></p>
</body>
</html>
18 changes: 18 additions & 0 deletions packages/e2e-test-app/static-fixtures/cookie.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function printCookie() {
document.getElementById('cookie_found').innerText = document.cookie;
}

document.cookie = 'test=TestData';
</script>
</head>
<body data-test-automation-id="root">
<button data-test-automation-id="cookie_clear_button" onclick="printCookie()">Cookie cleared!</button>
<p id="cookie_found" data-test-automation-id="cookie_found_text"></p>
</body>
</html>
35 changes: 35 additions & 0 deletions packages/e2e-test-app/static-fixtures/css.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.customDivClass {
background-color: darkred;
}

.becomeVisible {
visibility: hidden;
}
</style>
<script>
function showHidden() {
document.getElementById('becomeVisible').style.visibility = 'visible';
}

function hideVisible() {
document.getElementById('becomeHidden').style.visibility = 'hidden';
}
</script>
</head>
<body data-test-automation-id="root">
<div class="customDivClass" data-test-automation-id="withClass"></div>
<div style="background-color: red;" data-test-automation-id="withStyle"></div>

<div data-test-automation-id="becomeVisible" class="becomeVisible" id="becomeVisible">becomeVisible</div>
<div data-test-automation-id="becomeHidden" id="becomeHidden">becomeHidden</div>

<button data-test-automation-id="showHiddenButton" onclick="showHidden()">show hidden</button>
<button data-test-automation-id="hideVisibleButton" onclick="hideVisible()">hide visible</button>
</body>
</html>
16 changes: 16 additions & 0 deletions packages/e2e-test-app/static-fixtures/elements.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body data-test-automation-id="root">
<ul data-test-automation-id="existingElement">
<li data-test-automation-id="li"></li>
<li data-test-automation-id="li"></li>
<li data-test-automation-id="li"></li>
<li data-test-automation-id="li"></li>
<li data-test-automation-id="li"></li>
</ul>
</body>
</html>
41 changes: 41 additions & 0 deletions packages/e2e-test-app/static-fixtures/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body data-test-automation-id="root">
<form data-test-automation-id="form">
<div>
<label for="nameInput">Name: </label><input id="nameInput" type="text" placeholder="name" data-test-automation-id="nameInput">
</div>
<div>
<label for="disabledInput">disabled: </label>
<input id="disabledInput" type="text" placeholder="disabled" data-test-automation-id="disabledInput" disabled>
</div>
<div>
<label for="readonlyInput">readonly: </label>
<input id="readonlyInput" type="text" placeholder="readonly" data-test-automation-id="readonlyInput" readonly value="readonly">
</div>
<div>
<input id="checkbox" type="checkbox" data-test-automation-id="checkbox">
<label for="checkbox">checkbox label</label>
</div>
<div>
<input id="checkbox2" type="checkbox" data-test-automation-id="checkbox_2" checked="checked">
<label for="checkbox2">checkbox label with initial checked</label>
</div>
<div>
<label for="select">Choose: </label>
<select id="select" data-test-automation-id="select">
<option data-test-attr="value" value="byAttribute">By attribute</option>
<option name="testName" value="byName">By name</option>
<option value="byIndex">By index</option>
<option value="byValue">By value</option>
<option value="byVisibleText" id="select-option-visible-text">By visible text</option>
<option data-test-automation-id="option" value="withTestId" id="select-test-option">With test id</option>
</select>
</div>
</form>
</body>
</html>
29 changes: 29 additions & 0 deletions packages/e2e-test-app/static-fixtures/html-and-text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var addedForIds = [];

function appendText4(id) {
if (addedForIds.indexOf(id) !== -1) {
return;
}

document.getElementById(id).append('Text 4');
addedForIds.push(id);
}
</script>
</head>
<body data-test-automation-id="root">
<div data-test-automation-id="container"><p>test</p></div>
<div data-test-automation-id="text">Text is here!</div>
<div data-test-automation-id="texts" id="texts" onmouseover="appendText4('texts')">
<p>Text 1</p>
<p>Text 2</p>
<p>Text 3</p>
</div>
<div data-test-automation-id="textWithoutFocus" id="textWithoutFocus" onmouseover="appendText4('textWithoutFocus')">Text without focus</div>
</body>
</html>
29 changes: 29 additions & 0 deletions packages/e2e-test-app/static-fixtures/scroll.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Scroll test</title>
<style>
.container {
height: 200px;
width: 200px;
overflow: auto;
background: aliceblue;
}
</style>
</head>
<body data-test-automation-id="root">
<div class="container" data-test-automation-id="container" id="container">
<p data-test-automation-id="item_1" id="item_1">Text 1</p>
<p>Text 2</p>
<p>Text 3</p>
<p>Text 4</p>
<p>Text 5</p>
<p>Text 6</p>
<p data-test-automation-id="item_7">Text 7</p>
<p data-test-automation-id="item_8">Text 8</p>
<p>Text 9</p>
<p data-test-automation-id="item_10" id="item_10">Text 10</p>
</div>
</body>
</html>
15 changes: 15 additions & 0 deletions packages/e2e-test-app/static-fixtures/title.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>original title</title>
<script>
function changeTitle() {
document.title = 'title changed';
}
</script>
</head>
<body data-test-automation-id="root">
<button data-test-automation-id="changeTitleButton" onclick="changeTitle()">Change title</button>
</body>
</html>
20 changes: 20 additions & 0 deletions packages/e2e-test-app/static-fixtures/wait-for-exist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function showElement() {
setTimeout(() => {
const elem = document.createElement('div');
elem.setAttribute('data-test-automation-id', 'shouldExist');

document.body.prepend(elem);
}, 1000);
}
</script>
</head>
<body data-test-automation-id="root">
<button data-test-automation-id="showElement" onclick="showElement()">show</button>
</body>
</html>
18 changes: 18 additions & 0 deletions packages/e2e-test-app/test/selenium/test/alert.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { run } from 'testring';

run(async (api) => {
await api.application.url('http://localhost:8080/alert.html');

await api.application.alertAccept();
await api.application.alertDismiss();
const text = await api.application.alertText();

const firstAlertState = await api.application.getText(api.application.root.alerts.first);
const secondAlertState = await api.application.getText(api.application.root.alerts.second);
const thirdAlertState = await api.application.getText(api.application.root.alerts.third);

api.application.assert.equal(firstAlertState, 'true');
api.application.assert.equal(secondAlertState, 'false');
api.application.assert.equal(thirdAlertState, 'false');
api.application.assert.equal(text, 'test');
});
12 changes: 12 additions & 0 deletions packages/e2e-test-app/test/selenium/test/click.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { run } from 'testring';

run(async (api) => {
await api.application.url('http://localhost:8080/click.html');

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

const outputText = await api.application.getText(api.application.root.output);
api.application.assert.equal(outputText, 'test');
});
13 changes: 13 additions & 0 deletions packages/e2e-test-app/test/selenium/test/cookie.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { run } from 'testring';

run(async (api) => {
await api.application.url('http://localhost:8080/cookie.html');
const cookieValue = await api.application.getCookie('test');
await api.application.assert.equal(cookieValue, 'TestData');

await api.application.deleteCookie('test');
await api.application.click(api.application.root.cookie_clear_button);

const cookieTextAfterDelete = await api.application.getText(api.application.root.cookie_found_text);
await api.application.assert.equal(cookieTextAfterDelete, '');
});

0 comments on commit c1ee230

Please sign in to comment.