-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_spy_addon.js
More file actions
32 lines (26 loc) · 1.13 KB
/
04_spy_addon.js
File metadata and controls
32 lines (26 loc) · 1.13 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
const { Builder } = require('lanthan');
const { WebDriver, By } = require('selenium-webdriver');
const assert = require('assert');
const path = require('path');
(async () => {
let lanthan = await Builder
.forBrowser('firefox') // Lanthan currently supports only Firefox
.spyAddon(path.join(__dirname, 'addon')) // Spy to the addon
.build();
let webdriver = lanthan.getWebDriver();
let browser = lanthan.getWebExtBrowser();
// Press keys on example.com
await webdriver.navigate().to('https://example.com/');
await webdriver.findElement(By.css('body')).sendKeys('a');
// Press keys on example.org
await webdriver.navigate().to('https://example.org/');
await webdriver.findElement(By.css('body')).sendKeys('1');
await webdriver.findElement(By.css('body')).sendKeys('2');
await webdriver.findElement(By.css('body')).sendKeys('3');
// Assert counted keys
let { count } = await browser.storage.local.get('count');
assert.strictEqual(count['https://example.com'], 1);
assert.strictEqual(count['https://example.org'], 3);
assert.strictEqual(count['https://example.net'], undefined);
await lanthan.quit();
})()