Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit fadfd0a

Browse files
committed
update test
1 parent 43e59c9 commit fadfd0a

File tree

8 files changed

+201
-5951
lines changed

8 files changed

+201
-5951
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
example
1+
example
2+
src

example/Pages/CalculatorPage.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import { PageObject, By2 } from "selenium-appium";
7+
8+
class CalculatorPage extends PageObject {
9+
isPageLoaded() {
10+
return this.minusButton.isDisplayed();
11+
}
12+
13+
get resultTextBox() { return By2.nativeAccessibilityId('CalculatorResults');}
14+
get equalButton() { return By2.nativeAccessibilityId('equalButton'); }
15+
get clearButton() { return By2.nativeName('Clear'); }
16+
get plusButton() { return By2.nativeName('Plus'); }
17+
get divideButton() { return By2.nativeAccessibilityId('divideButton'); }
18+
get multiplyButton() { return By2.nativeXpath("//Button[@Name='Multiply by']") }
19+
get minusButton() { return By2.nativeXpath("//Button[@AutomationId=\"minusButton\"]"); }
20+
get button0() { return By2.nativeAccessibilityId('num0Button'); }
21+
get button1() { return By2.nativeAccessibilityId('num1Button'); }
22+
get button2() { return By2.nativeAccessibilityId('num2Button'); }
23+
get button3() { return By2.nativeAccessibilityId('num3Button'); }
24+
get button4() { return By2.nativeAccessibilityId('num4Button'); }
25+
get button5() { return By2.nativeAccessibilityId('num5Button'); }
26+
get button6() { return By2.nativeAccessibilityId('num6Button'); }
27+
get button7() { return By2.nativeAccessibilityId('num7Button'); }
28+
get button8() { return By2.nativeAccessibilityId('num8Button'); }
29+
get button9() { return By2.nativeAccessibilityId('num9Button'); }
30+
31+
private async pressKeys(keys: string) {
32+
for (var key of keys) {
33+
await By2.nativeAccessibilityId('num' + key + 'Button').click();
34+
}
35+
}
36+
async divid(a: string, b: string): Promise<string> {
37+
await this.pressKeys(a);
38+
await this.divideButton.click();
39+
await this.pressKeys(b);
40+
await this.equalButton.click();
41+
return await this.getCalculatorResultText();
42+
}
43+
44+
async multiply(a: string, b: string): Promise<string> {
45+
await this.pressKeys(a);
46+
await this.multiplyButton.click();
47+
await this.pressKeys(b);
48+
await this.equalButton.click();
49+
return await this.getCalculatorResultText();
50+
}
51+
52+
async plus(a: string, b: string): Promise<string> {
53+
await this.pressKeys(a);
54+
await this.plusButton.click();
55+
await this.pressKeys(b);
56+
await this.equalButton.click();
57+
return await this.getCalculatorResultText();
58+
}
59+
60+
async minus(a: string, b: string): Promise<string> {
61+
await this.pressKeys(a);
62+
await this.minusButton.click();
63+
await this.pressKeys(b);
64+
await this.equalButton.click();
65+
return await this.getCalculatorResultText();
66+
}
67+
68+
private async getCalculatorResultText(): Promise<string> {
69+
return (await this.resultTextBox.getText()).replace('Display is', '').trim();
70+
}
71+
72+
}
73+
74+
export default new CalculatorPage();
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import { driver, By2, windowsAppDriverCapabilities } from 'selenium-appium'
7+
8+
jest.setTimeout(50000);
9+
10+
const calculatorAppId = 'Microsoft.WindowsCalculator_8wekyb3d8bbwe!App'
11+
const capabilites = windowsAppDriverCapabilities(calculatorAppId)
12+
13+
beforeAll(() => {
14+
return driver.startWithCapabilities(capabilites);
15+
});
16+
17+
afterAll(() => {
18+
return driver.quit();
19+
});
20+
21+
async function getCalculatorResultText() {
22+
const text = await By2.nativeAccessibilityId('CalculatorResults').getText();
23+
return text.replace('Display is', '').trim();
24+
}
25+
26+
describe('Addition', () => {
27+
// Applies only to tests in this describe block
28+
beforeEach(() => {
29+
return By2.nativeName('Clear').clear();
30+
});
31+
test('Addition', async () => {
32+
// Find the buttons by their names and click them in sequence to perform 1 + 7 = 8
33+
await By2.nativeName('One').click();
34+
await By2.nativeName('Plus').click();
35+
await By2.nativeName('Seven').click();
36+
await By2.nativeName('Equals').click();
37+
expect(await getCalculatorResultText()).toBe('8');
38+
});
39+
40+
test('Division', async () => {
41+
// Find the buttons by their accessibility ids and click them in sequence to perform 88 / 11 = 8
42+
await By2.nativeAccessibilityId('num8Button').click();
43+
await By2.nativeAccessibilityId('num8Button').click();
44+
await By2.nativeAccessibilityId('divideButton').click();
45+
await By2.nativeAccessibilityId('num1Button').click();
46+
await By2.nativeAccessibilityId('num1Button').click();
47+
await By2.nativeAccessibilityId('equalButton').click();
48+
expect(await getCalculatorResultText()).toBe('8');
49+
});
50+
51+
test('Multiplication', async () => {
52+
// Find the buttons by their names using XPath and click them in sequence to perform 9 x 9 = 81
53+
await By2.nativeXpath("//Button[@Name='Nine']").click();
54+
await By2.nativeXpath("//Button[@Name='Multiply by']").click();
55+
await By2.nativeXpath("//Button[@Name='Nine']").click();
56+
await By2.nativeXpath("//Button[@Name='Equals']").click();
57+
expect(await getCalculatorResultText()).toBe('81');
58+
});
59+
60+
61+
62+
test('Subtraction', async () => {
63+
// Find the buttons by their accessibility ids using XPath and click them in sequence to perform 9 - 1 = 8
64+
await By2.nativeXpath("//Button[@AutomationId=\"num9Button\"]").click();
65+
await By2.nativeXpath("//Button[@AutomationId=\"minusButton\"]").click();
66+
await By2.nativeXpath("//Button[@AutomationId=\"num1Button\"]").click();
67+
await By2.nativeXpath("//Button[@AutomationId=\"equalButton\"]").click();
68+
expect(await getCalculatorResultText()).toBe('8');
69+
});
70+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import { driver, By2, windowsAppDriverCapabilities } from 'selenium-appium'
7+
import CalculatorPage from '../Pages/CalculatorPage'
8+
9+
jest.setTimeout(50000);
10+
11+
const calculatorAppId = 'Microsoft.WindowsCalculator_8wekyb3d8bbwe!App'
12+
const capabilites = windowsAppDriverCapabilities(calculatorAppId)
13+
14+
beforeAll(() => {
15+
return driver.startWithCapabilities(capabilites);
16+
});
17+
18+
afterAll(() => {
19+
return driver.quit();
20+
});
21+
22+
23+
describe('Addition', () => {
24+
// Applies only to tests in this describe block
25+
beforeEach(async () => {
26+
await CalculatorPage.waitForPageLoaded();
27+
await CalculatorPage.clearButton.clear();
28+
});
29+
test('Addition', async () => {
30+
// Find the buttons by their names and click them in sequence to perform 1 + 7 = 8
31+
expect(await CalculatorPage.plus('1', '7')).toBe('8');
32+
});
33+
34+
test('Division', async () => {
35+
// Find the buttons by their accessibility ids and click them in sequence to perform 88 / 11 = 8
36+
expect(await CalculatorPage.divid('88', '11')).toBe('8');
37+
});
38+
39+
test('Multiplication', async () => {
40+
// Find the buttons by their names using XPath and click them in sequence to perform 9 x 9 = 81
41+
expect(await CalculatorPage.multiply('9', '9')).toBe('81');
42+
});
43+
44+
45+
46+
test('Subtraction', async () => {
47+
// Find the buttons by their accessibility ids using XPath and click them in sequence to perform 9 - 1 = 8
48+
expect(await CalculatorPage.minus('9', '1')).toBe('8');
49+
});
50+
});

example/__tests__/calculator.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)