-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestable-commands.js
More file actions
99 lines (86 loc) · 3.87 KB
/
testable-commands.js
File metadata and controls
99 lines (86 loc) · 3.87 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
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
const { chromium } = require('playwright');
const { URLSearchParams } = require('url');
(async () => {
try {
const start = Date.now();
const params = new URLSearchParams({
// API key (Org Management => API Keys)
key: process.env.TESTABLE_KEY,
// browser name: chrome, edge, firefox
browserName: 'chrome',
// browser version (e.g. latest, latest-1, 90)
browserVersion: 'latest',
// size of the display (WxH)
screenResolution: '1920x1080',
// The region in which to run your test (use our remote configurator to see the full list of options)
region: 'aws-us-east-1'
}).toString();
const browser = await chromium.connect(
`wss://playwright.testable.io?${params}`,
{ timeout: 0 });
const page = await browser.newPage();
await page.setViewportSize({ width: 1920, height: 1080 });
// Returns Testable information related to this run: { executionId, sessionId }
// If you specified a keepAlive time, use the sessionId as a parameter when reconnecting.
// The executionId allows you to retrieve information about this run via the API or front-end.
const info = await page.evaluate(function testable_info() {});
console.log(`Testable info: ${JSON.stringify(info)}`);
// Indicates the start of a test step - you can see progress live on the test result page
await page.evaluate(function testable_assertion_start() { }, {
suite: 'Streaming suite',
name: 'Loading Google and sleeping a while'
});
await page.goto('https://www.google.com');
await page.waitForTimeout(1000);
// Indicate that we are finishing the test step - updates live on the test results page
await page.evaluate(function testable_assertion_finish() { }, {
state: 'passed',
screenshot: true
});
// Capture something into the test log. Log levels include: trace, debug, info, error, fatal
await page.evaluate(function testable_log() { }, [ 'info', 'Some information I want to capture' ]);
// mark the test as having failed (testable_pass() {} to mark it as passed)
await page.evaluate(function testable_fail() { });
// counter metric - see our documentation for more details about metrics
await page.evaluate(function testable_metric() { }, [ 'counter', {
name: '# of Orders',
val: 5,
units: 'orders'
} ]);
// timing metric
await page.evaluate(function testable_metric() { }, [ 'timing', {
name: 'Order Execution Time',
val: 534,
units: 'ms'
} ]);
// histogram metric where the "key" indicates the bucket
await page.evaluate(function testable_metric() { }, [ 'histogram', {
name: 'Orders By Type',
key: 'Online',
val: 5
} ]);
// metered metric where the "key" indicates the bucket
await page.evaluate(function testable_metric() { }, [ 'metered', {
name: 'Server Memory Usage',
key: 'server123',
val: 34524232,
units: 'bytes'
} ]);
// an assertion
await page.evaluate(function testable_assertion() { }, {
suite: 'Example test suite',
name: 'Load Google and check title',
duration: Date.now() - start,
state: 'failed',
screenshot: true,
errorType: 'TEST_ERROR',
error: 'Demo error',
errorTrace: 'More details about the demo error'
});
// screenshosts are also captured into the test results
await page.screenshot({ path: 'test.png' });
browser.close();
} catch (err) {
console.log(err);
}
})();