forked from appium/appium-xcuitest-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert-e2e-specs.js
119 lines (100 loc) · 3.29 KB
/
alert-e2e-specs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import B from 'bluebird';
import {retryInterval} from 'asyncbox';
import {amendCapabilities, UICATALOG_CAPS, UICATALOG_BUNDLE_ID} from '../desired';
import {initSession, deleteSession, getUsePrebuiltWDACaps, MOCHA_TIMEOUT} from '../helpers/session';
chai.should();
chai.use(chaiAsPromised);
describe('XCUITestDriver - alerts -', function () {
this.timeout(MOCHA_TIMEOUT);
let driver;
before(async function () {
const caps = amendCapabilities(UICATALOG_CAPS, await getUsePrebuiltWDACaps());
driver = await initSession(caps);
});
after(async function () {
try {
await driver.terminateApp(UICATALOG_BUNDLE_ID);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
await deleteSession();
});
beforeEach(async function () {
await retryInterval(5, 500, async () => {
let el = await driver.$('~Alert Views');
await el.click();
(await driver.$$('~Simple')).should.have.length(1);
});
});
afterEach(async function () {
try {
await driver.dismissAlert();
} catch (ign) {}
await driver.back();
});
it('should detect Simple', async function () {
let el = await driver.$('~Simple');
await el.click();
await B.delay(2000);
(await driver.getAlertText()).should.include('A Short Title Is Best');
await driver.dismissAlert();
});
it('should detect Okay', async function () {
let el = await driver.$('~Okay / Cancel');
await el.click();
// small pause for alert to open
await B.delay(1000);
(await driver.getAlertText()).should.include('A Short Title Is Best');
await driver.acceptAlert();
});
it('should detect Other', async function () {
let el = await driver.$('~Other');
await el.click();
// small pause for alert to open
await B.delay(1000);
(await driver.getAlertText()).should.include('A Short Title Is Best');
await driver.dismissAlert();
});
describe('prompt -', function () {
const testData = [
{
name: 'text field',
alert: 'Text Entry',
field: 'XCUIElementTypeTextField',
text: 'hello world',
expectedText: 'hello world',
},
{
name: 'secure text field',
alert: 'Secure Text Entry',
field: 'XCUIElementTypeSecureTextField',
text: 'hello world',
expectedText: '•••••••••••',
},
];
for (const test of testData) {
it(`should be able to interact with a prompt with a ${test.name}`, async function () {
let el = await driver.$(`~${test.alert}`);
await el.click();
// small pause for alert to open
await B.delay(1000);
await driver.sendAlertText(test.text);
let textField = await driver.$(test.field);
let text = await textField.getText();
text.should.equal(test.expectedText);
// on some devices the keyboard obscurs the buttons so no dismiss is possible
await textField.setValue('\n');
});
}
});
it('should throw a NoAlertOpenError when no alert is open', async function () {
await driver
.acceptAlert()
.should.be.rejectedWith(
/An attempt was made to operate on a modal dialog when one was not open/,
);
});
});