forked from stoneman/appium-windows-driver
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathfile-movement-e2e-specs.ts
More file actions
69 lines (56 loc) · 2.18 KB
/
file-movement-e2e-specs.ts
File metadata and controls
69 lines (56 loc) · 2.18 KB
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
import { remote as wdio } from 'webdriverio';
import type { Browser } from 'webdriverio';
import path from 'node:path';
import { tempDir, fs } from 'appium/support';
import { isAdmin } from '../../../lib/installer';
import { buildWdIoOptions } from '../helpers';
import { expect } from 'chai';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised.default);
describe('file movement', function () {
let driver: Browser | null = null;
let remotePath: string | null = null;
beforeEach(async function () {
if (process.env.CI || !await isAdmin()) {
return this.skip();
}
driver = await wdio(buildWdIoOptions('Root'));
});
afterEach(async function () {
try {
if (driver) {
await driver.deleteSession();
}
if (remotePath) {
if (await fs.exists(remotePath)) {
await fs.rimraf(path.dirname(remotePath));
}
}
} finally {
remotePath = null;
driver = null;
}
});
it('should push and pull a file', async function () {
const stringData = `random string data ${Math.random()}`;
const base64Data = Buffer.from(stringData).toString('base64');
remotePath = await tempDir.path({ prefix: 'appium', suffix: '.tmp' });
await driver!.pushFile(remotePath, base64Data);
// get the file and its contents, to check
const remoteData64 = await driver!.pullFile(remotePath);
const remoteData = Buffer.from(remoteData64, 'base64').toString();
expect(remoteData).to.equal(stringData);
});
it('should be able to delete a file', async function () {
const stringData = `random string data ${Math.random()}`;
const base64Data = Buffer.from(stringData).toString('base64');
remotePath = await tempDir.path({ prefix: 'appium', suffix: '.tmp' });
await driver!.pushFile(remotePath, base64Data);
const remoteData64 = await driver!.pullFile(remotePath);
const remoteData = Buffer.from(remoteData64, 'base64').toString();
expect(remoteData).to.equal(stringData);
await driver!.execute('windows: deleteFile', { remotePath });
await expect(driver!.pullFile(remotePath)).to.eventually.be.rejectedWith(/does not exist/);
});
});