Skip to content

Commit 682e639

Browse files
committed
add example
1 parent 4f7881e commit 682e639

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

example/__tests__/calculator.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { createAppiumWebDriver, windowsNativeAppCapabilities } from 'selenium-appium'
2+
import { By } from 'selenium-webdriver'
3+
jest.setTimeout(50000);
4+
5+
const calculatorAppId = 'Microsoft.WindowsCalculator_8wekyb3d8bbwe!App'
6+
const driver = createAppiumWebDriver(windowsNativeAppCapabilities(calculatorAppId))
7+
8+
beforeAll(() => {
9+
return driver.start();
10+
});
11+
12+
afterAll(() => {
13+
return driver.stop();
14+
});
15+
16+
async function getCalculatorResultText() {
17+
const text = await driver.getByAccessibilityId('CalculatorResults').getText();
18+
return text.replace('Display is', '').trim();
19+
}
20+
21+
describe('Addition', () => {
22+
// Applies only to tests in this describe block
23+
beforeEach(async () => {
24+
await driver.getByName('Clear').clear();
25+
});
26+
27+
test('Addition', async () => {
28+
// Find the buttons by their names and click them in sequence to perform 1 + 7 = 8
29+
await driver.getByName('One').click();
30+
await driver.getByName('Plus').click();
31+
await driver.getByName('Seven').click();
32+
await driver.getByName('Equals').click();
33+
expect(await getCalculatorResultText()).toBe('8');
34+
});
35+
36+
test('Division', async () => {
37+
// Find the buttons by their accessibility ids and click them in sequence to perform 88 / 11 = 8
38+
await driver.getByAccessibilityId('num8Button').click();
39+
await driver.getByAccessibilityId('num8Button').click();
40+
await driver.getByAccessibilityId('divideButton').click();
41+
await driver.getByAccessibilityId('num1Button').click();
42+
await driver.getByAccessibilityId('num1Button').click();
43+
await driver.getByAccessibilityId('equalButton').click();
44+
expect(await getCalculatorResultText()).toBe('8');
45+
});
46+
47+
test('Multiplication', async () => {
48+
// Find the buttons by their names using XPath and click them in sequence to perform 9 x 9 = 81
49+
await driver.get(By.xpath("//Button[@Name='Nine']")).click();
50+
await driver.get(By.xpath("//Button[@Name='Multiply by']")).click();
51+
await driver.get(By.xpath("//Button[@Name='Nine']")).click();
52+
await driver.get(By.xpath("//Button[@Name='Equals']")).click();
53+
expect(await getCalculatorResultText()).toBe('81');
54+
});
55+
56+
57+
58+
test('Subtraction', async () => {
59+
// Find the buttons by their accessibility ids using XPath and click them in sequence to perform 9 - 1 = 8
60+
await driver.get(By.xpath("//Button[@AutomationId=\"num9Button\"]")).click();
61+
await driver.get(By.xpath("//Button[@AutomationId=\"minusButton\"]")).click();
62+
await driver.get(By.xpath("//Button[@AutomationId=\"num1Button\"]")).click();
63+
await driver.get(By.xpath("//Button[@AutomationId=\"equalButton\"]")).click();
64+
expect(await getCalculatorResultText()).toBe('8');
65+
});
66+
});

example/babel.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current',
8+
},
9+
},
10+
], '@babel/preset-typescript',
11+
],
12+
};

example/package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "example",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"appium": "appium",
8+
"jest": "jest"
9+
},
10+
"keywords": [],
11+
"author": "Canhua Li <licanhua@live.com> (https://github.com/licanhua)",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@babel/core": "^7.5.5",
15+
"@babel/preset-env": "^7.5.5",
16+
"@babel/preset-typescript": "^7.3.3",
17+
"@types/selenium-webdriver": "^4.0.1",
18+
"babel-jest": "^24.8.0",
19+
"jest": "^24.8.0",
20+
"selenium-appium": "^0.0.3",
21+
"selenium-webdriver": "^4.0.0-alpha.4",
22+
"typescript": "^3.5.3"
23+
},
24+
"dependencies": {
25+
"@types/jest": "^24.0.17"
26+
}
27+
}

example/yarn-error.log

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Arguments:
2+
C:\Program Files\nodejs\node.exe C:\Users\lican\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js add appium appium-selenium selenium-webdriver -D
3+
4+
PATH:
5+
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Users\lican\AppData\Local\Microsoft\WindowsApps;C:\Users\lican\AppData\Roaming\npm;C:\Users\lican\AppData\Local\Programs\Microsoft VS Code\bin;
6+
7+
Yarn version:
8+
1.12.1
9+
10+
Node version:
11+
8.12.0
12+
13+
Platform:
14+
win32 x64
15+
16+
Trace:
17+
Error: https://registry.yarnpkg.com/appium-selenium: Not found
18+
at Request.params.callback [as _callback] (C:\Users\lican\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:62126:18)
19+
at Request.self.callback (C:\Users\lican\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:124482:22)
20+
at emitTwo (events.js:126:13)
21+
at Request.emit (events.js:214:7)
22+
at Request.<anonymous> (C:\Users\lican\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:125454:10)
23+
at emitOne (events.js:116:13)
24+
at Request.emit (events.js:211:7)
25+
at IncomingMessage.<anonymous> (C:\Users\lican\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:125376:12)
26+
at Object.onceWrapper (events.js:313:30)
27+
at emitNone (events.js:111:20)
28+
29+
npm manifest:
30+
{
31+
"name": "example",
32+
"version": "1.0.0",
33+
"description": "",
34+
"main": "index.js",
35+
"scripts": {
36+
"test": "echo \"Error: no test specified\" && exit 1"
37+
},
38+
"keywords": [],
39+
"author": "Canhua Li <licanhua@live.com> (https://github.com/licanhua)",
40+
"license": "ISC"
41+
}
42+
43+
yarn manifest:
44+
No manifest
45+
46+
Lockfile:
47+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
48+
# yarn lockfile v1

0 commit comments

Comments
 (0)