-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
72 lines (62 loc) · 2.05 KB
/
Copy pathutils.js
File metadata and controls
72 lines (62 loc) · 2.05 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
70
71
72
const fs = require('fs');
const path = require('path');
const { remote } = require('webdriverio');
require('dotenv').config();
const PCLOUDY_USERNAME = process.env.PCLOUDY_USERNAME || '';
const PCLOUDY_APIKEY = process.env.PCLOUDY_APIKEY || '';
function ensureScreenshotsDir() {
const dir = path.join(process.cwd(), 'screenshots');
fs.mkdirSync(dir, { recursive: true });
return dir;
}
async function captureScreenshot(driver, label) {
const dir = ensureScreenshotsDir();
const filePath = path.join(dir, `${label}-${Date.now()}.png`);
await driver.saveScreenshot(filePath);
console.log(`Saved screenshot: ${filePath}`);
}
async function waitForElement(driver, selector, timeout = 20000) {
const element = await driver.$(selector);
await element.waitForDisplayed({ timeout });
return element;
}
function validatePcloudyCredentials() {
const placeholderPatterns = [/^sample_/i, /^your_/i, /^YOUR_/i, /^changeme$/i, /^<.*>$/];
const isPlaceholder = (value) => !value || placeholderPatterns.some((pattern) => pattern.test(value));
if (isPlaceholder(PCLOUDY_USERNAME) || isPlaceholder(PCLOUDY_APIKEY)) {
throw new Error(
'pCloudy credentials are not configured. Update the .env file with your real PCLOUDY_USERNAME and PCLOUDY_APIKEY values before running the sample.'
);
}
}
async function createDriver(capabilities) {
validatePcloudyCredentials();
return remote({
protocol: 'https',
hostname: 'device.pcloudy.com',
port: 443,
path: '/appiumcloud/wd/hub',
logLevel: 'info',
capabilities
});
}
function buildCommonPcloudyOptions(deviceFullName, enableVideo = true) {
return {
pCloudy_Username: PCLOUDY_USERNAME,
pCloudy_ApiKey: PCLOUDY_APIKEY,
pCloudy_DeviceFullName: deviceFullName,
pCloudy_WildNet: false,
pCloudy_EnableVideo: enableVideo,
pCloudy_EnablePerformanceData: false,
pCloudy_EnableDeviceLogs: false,
appiumVersion: '3.1.1'
};
}
module.exports = {
captureScreenshot,
waitForElement,
createDriver,
buildCommonPcloudyOptions,
PCLOUDY_USERNAME,
PCLOUDY_APIKEY
};