-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathwindows.spec.js
63 lines (52 loc) · 2.35 KB
/
windows.spec.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
const {Builder, By} = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const assert = require("node:assert");
let opts = new chrome.Options();
opts.addArguments('--headless');
let startIndex = 0
let endIndex = 5
let pdfMagicNumber = 'JVBER'
let imgMagicNumber = 'iVBOR'
let base64Code
describe('Interactions - Windows', function () {
let driver;
before(async function () {
driver = await new Builder().forBrowser('chrome').setChromeOptions(opts).build();
});
after(async () => await driver.quit());
it('Should be able to print page to pdf', async function () {
await driver.get('https://www.selenium.dev/selenium/web/alerts.html');
let base64 = await driver.printPage({pageRanges: ["1-2"]});
// page can be saved as a PDF as below
// await fs.writeFileSync('./test.pdf', base64, 'base64');
base64Code = base64.slice(startIndex, endIndex)
assert.strictEqual(base64Code, pdfMagicNumber)
});
it('Should be able to get text using executeScript', async function () {
await driver.get('https://www.selenium.dev/selenium/web/javascriptPage.html');
// Stores the header element
let header = await driver.findElement(By.css('h1'));
// Executing JavaScript to capture innerText of header element
let text = await driver.executeScript('return arguments[0].innerText', header);
assert.strictEqual(text, `Type Stuff`)
});
it('Should be able to take Element Screenshot', async function () {
await driver.get('https://www.selenium.dev/selenium/web/javascriptPage.html');
let header = await driver.findElement(By.css('h1'));
// Captures the element screenshot
let encodedString = await header.takeScreenshot(true);
// save screenshot as below
// await fs.writeFileSync('./image.png', encodedString, 'base64');
base64Code = encodedString.slice(startIndex, endIndex)
assert.strictEqual(base64Code, imgMagicNumber)
});
it('Should be able to takeScreenshot', async function () {
await driver.get('https://www.selenium.dev/selenium/web/javascriptPage.html');
// Captures the screenshot
let encodedString = await driver.takeScreenshot();
// save screenshot as below
// await fs.writeFileSync('./image.png', encodedString, 'base64');
base64Code = encodedString.slice(startIndex, endIndex)
assert.strictEqual(base64Code, imgMagicNumber)
});
});