1 | import { expectError, expectType } from 'tsd';
|
2 | import { AppiumGeolocation, NightwatchAPI } from '..';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | describe('orientation commands', function () {
|
8 | it('tests orientation commands', function () {
|
9 | expectType<NightwatchAPI>(app);
|
10 | expectType<boolean>(app.isAppiumClient());
|
11 |
|
12 | app.appium
|
13 | .getOrientation(function (result) {
|
14 | expectType<NightwatchAPI>(this);
|
15 | if (result.status === 0) {
|
16 | expectType<'LANDSCAPE' | 'PORTRAIT'>(result.value);
|
17 | }
|
18 | })
|
19 | .appium.setOrientation('LANDSCAPE', function (result) {
|
20 | expectType<NightwatchAPI>(this);
|
21 | if (result.status === 0) {
|
22 | expectType<'LANDSCAPE' | 'PORTRAIT'>(result.value);
|
23 | }
|
24 | });
|
25 | });
|
26 |
|
27 | it('tests orientation commands with async/await', async function () {
|
28 | expectType<NightwatchAPI>(app);
|
29 | expectType<boolean>(app.isAppiumClient());
|
30 |
|
31 | const orientation = await app.appium.getOrientation();
|
32 | expectType<'LANDSCAPE' | 'PORTRAIT'>(orientation);
|
33 |
|
34 | const result = await app.appium.setOrientation('PORTRAIT');
|
35 | expectType<'LANDSCAPE' | 'PORTRAIT'>(result);
|
36 | });
|
37 | });
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | describe('context commands', function () {
|
43 | it('tests context commands', function (app: NightwatchAPI) {
|
44 | expectType<boolean>(app.isAppiumClient());
|
45 |
|
46 | app.appium
|
47 | .getContexts(function (result) {
|
48 | expectType<NightwatchAPI>(this);
|
49 | if (result.status === 0) {
|
50 | expectType<string[]>(result.value);
|
51 | }
|
52 | })
|
53 | .appium.getContext(function (result) {
|
54 | expectType<NightwatchAPI>(this);
|
55 | if (result.status === 0) {
|
56 | expectType<string | null>(result.value);
|
57 | }
|
58 | })
|
59 | .appium.setContext('something', function (result) {
|
60 | expectType<NightwatchAPI>(this);
|
61 | if (result.status === 0) {
|
62 | expectType<null>(result.value);
|
63 | }
|
64 | });
|
65 | });
|
66 |
|
67 | it('tests context commands with async/await', async function (app: NightwatchAPI) {
|
68 | expectType<boolean>(app.isAppiumClient());
|
69 |
|
70 | const contexts = await app.appium.getContexts();
|
71 | expectType<string[]>(contexts);
|
72 |
|
73 | const context = await app.appium.getContext();
|
74 | expectType<string | null>(context);
|
75 |
|
76 | const result = await app.appium.setContext('random');
|
77 | expectType<null>(result);
|
78 | });
|
79 | });
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | describe('activity commands', function () {
|
85 | it('tests activity commands', function (app: NightwatchAPI) {
|
86 | app.appium
|
87 | .startActivity(
|
88 | {
|
89 | appPackage: 'com.some.package',
|
90 | appActivity: 'some.activity',
|
91 | },
|
92 | function (result) {
|
93 | expectType<NightwatchAPI>(this);
|
94 | if (result.status === 0) {
|
95 | expectType<null>(result.value);
|
96 | }
|
97 | }
|
98 | )
|
99 | .appium.getCurrentActivity(function (result) {
|
100 | expectType<NightwatchAPI>(this);
|
101 | if (result.status === 0) {
|
102 | expectType<string>(result.value);
|
103 | }
|
104 | })
|
105 | .appium.getCurrentPackage(function (result) {
|
106 | expectType<NightwatchAPI>(this);
|
107 | if (result.status === 0) {
|
108 | expectType<string>(result.value);
|
109 | }
|
110 | });
|
111 | });
|
112 |
|
113 | it('tests activity commands with async/await', async function (app: NightwatchAPI) {
|
114 | expectError(await app.appium.startActivity({
|
115 | appPackage: 'com.something',
|
116 | }))
|
117 |
|
118 | const result = await app.appium.startActivity({
|
119 | appPackage: 'com.something',
|
120 | appActivity: 'some.activity',
|
121 | appWaitActivity: 'some.other.activity',
|
122 | });
|
123 | expectType<null>(result);
|
124 |
|
125 | const activity = await app.appium.getCurrentActivity();
|
126 | expectType<string>(activity);
|
127 |
|
128 | const packageName = await app.appium.getCurrentPackage();
|
129 | expectType<string>(packageName);
|
130 | });
|
131 | });
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | describe('geolocation commands', function () {
|
137 | it('tests geolocation commands', function (app: NightwatchAPI) {
|
138 | app.appium
|
139 | .getGeolocation(function (result) {
|
140 | expectType<NightwatchAPI>(this);
|
141 | if (result.status === 0) {
|
142 | expectType<AppiumGeolocation>(result.value);
|
143 | }
|
144 | })
|
145 | .appium.setGeolocation({ latitude: 232, longitude: 2343, altitude: 5 }, function (result) {
|
146 | expectType<NightwatchAPI>(this);
|
147 | if (result.status === 0) {
|
148 | expectType<AppiumGeolocation>(result.value);
|
149 | }
|
150 | });
|
151 | });
|
152 |
|
153 | it('tests geolocation commands with async/await', async function (app: NightwatchAPI) {
|
154 | const location = await app.appium.getGeolocation();
|
155 | expectType<AppiumGeolocation>(location);
|
156 | expectError(await app.appium.setGeolocation({ latitude: 543 }))
|
157 | expectError(await app.appium.setGeolocation())
|
158 |
|
159 | const result = await app.appium.setGeolocation({ latitude: 232, longitude: 2343 });
|
160 | expectType<AppiumGeolocation>(result);
|
161 | });
|
162 | });
|
163 |
|
164 |
|
165 |
|
166 |
|
167 | describe('keyboard interaction commands', function () {
|
168 | it('tests keyboard interaction commands', function (app: NightwatchAPI) {
|
169 | app.appium
|
170 | .pressKeyCode(35, function (result) {
|
171 | expectType<NightwatchAPI>(this);
|
172 | if (result.status === 0) {
|
173 | expectType<null>(result.value);
|
174 | }
|
175 | })
|
176 | .appium.longPressKeyCode(31, function (result) {
|
177 | expectType<NightwatchAPI>(this);
|
178 | if (result.status === 0) {
|
179 | expectType<null>(result.value);
|
180 | }
|
181 | })
|
182 | .appium.hideKeyboard(function (result) {
|
183 | expectType<NightwatchAPI>(this);
|
184 | if (result.status === 0) {
|
185 | expectType<boolean>(result.value);
|
186 | }
|
187 | })
|
188 | .appium.isKeyboardShown(function (result) {
|
189 | expectType<NightwatchAPI>(this);
|
190 | if (result.status === 0) {
|
191 | expectType<boolean>(result.value);
|
192 | }
|
193 | });
|
194 | });
|
195 |
|
196 | it('tests keyboard interaction commands with async/await', async function (app: NightwatchAPI) {
|
197 | expectError(await app.appium.pressKeyCode())
|
198 | expectError(await app.appium.pressKeyCode(32, 45, () => {}))
|
199 |
|
200 | await app.appium.pressKeyCode(56, () => {});
|
201 | await app.appium.pressKeyCode(44, undefined, undefined, () => {});
|
202 |
|
203 | const result = await app.appium.pressKeyCode(34, 29474, undefined, () => {});
|
204 | expectType<null>(result);
|
205 |
|
206 | expectError(await app.appium.longPressKeyCode())
|
207 | expectError(await app.appium.longPressKeyCode(32, 45, () => {}))
|
208 |
|
209 | await app.appium.longPressKeyCode(56, () => {});
|
210 | await app.appium.longPressKeyCode(44, undefined, undefined, () => {});
|
211 |
|
212 | const result2 = await app.appium.longPressKeyCode(34, 29474, undefined, () => {});
|
213 | expectType<null>(result2);
|
214 |
|
215 | const result3 = await app.appium.hideKeyboard();
|
216 | expectType<boolean>(result3);
|
217 |
|
218 | const result4 = await app.appium.isKeyboardShown();
|
219 | expectType<boolean>(result4);
|
220 | });
|
221 |
|
222 | it('test reset app commands', async function (app: NightwatchAPI) {
|
223 | const result = await app.appium.resetApp();
|
224 | expectType<null>(result);
|
225 | });
|
226 | });
|