2020-10-26 15:18:23 +03:00
|
|
|
import { resolve } from 'path';
|
|
|
|
import webdriver from 'selenium-webdriver';
|
2021-10-21 17:15:09 +03:00
|
|
|
import chrome from 'selenium-webdriver/chrome';
|
2023-08-19 05:14:30 +03:00
|
|
|
import chromedriver from 'chromedriver115';
|
2020-10-26 15:18:23 +03:00
|
|
|
import { switchMonitorTests, delay } from '../utils/e2e';
|
|
|
|
|
|
|
|
const port = 9515;
|
2022-11-07 03:26:12 +03:00
|
|
|
const path = resolve(__dirname, '..', '..', 'dist');
|
2020-10-26 15:18:23 +03:00
|
|
|
const extensionId = 'lmhkpmbekcpmknklioeibfkpmmfibljd';
|
2021-06-18 06:56:36 +03:00
|
|
|
const actionsPattern =
|
|
|
|
/^@@INIT(.|\n)+@@reduxReactRouter\/routerDidChange(.|\n)+@@reduxReactRouter\/initRoutes(.|\n)+$/;
|
2020-10-26 15:18:23 +03:00
|
|
|
|
|
|
|
describe('Chrome extension', function () {
|
2021-08-27 19:08:40 +03:00
|
|
|
let driver;
|
|
|
|
|
2020-12-19 23:01:09 +03:00
|
|
|
beforeAll(async () => {
|
2020-11-17 03:57:35 +03:00
|
|
|
chromedriver.start();
|
2020-10-26 15:18:23 +03:00
|
|
|
await delay(2000);
|
2021-08-27 19:08:40 +03:00
|
|
|
driver = new webdriver.Builder()
|
2020-10-26 15:18:23 +03:00
|
|
|
.usingServer(`http://localhost:${port}`)
|
2021-10-21 17:15:09 +03:00
|
|
|
.setChromeOptions(
|
2023-07-12 21:03:20 +03:00
|
|
|
new chrome.Options().addArguments(`load-extension=${path}`),
|
2021-10-21 17:15:09 +03:00
|
|
|
)
|
2020-10-26 15:18:23 +03:00
|
|
|
.forBrowser('chrome')
|
|
|
|
.build();
|
|
|
|
});
|
2021-08-27 19:08:40 +03:00
|
|
|
|
2020-12-19 23:01:09 +03:00
|
|
|
afterAll(async () => {
|
2021-08-27 19:08:40 +03:00
|
|
|
await driver.quit();
|
2020-11-17 03:57:35 +03:00
|
|
|
chromedriver.stop();
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should open extension's window", async () => {
|
2021-08-27 19:08:40 +03:00
|
|
|
await driver.get(`chrome-extension://${extensionId}/window.html#left`);
|
|
|
|
const url = await driver.getCurrentUrl();
|
2020-10-26 15:18:23 +03:00
|
|
|
expect(url).toBe(`chrome-extension://${extensionId}/window.html#left`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should match document title', async () => {
|
2021-08-27 19:08:40 +03:00
|
|
|
const title = await driver.getTitle();
|
2020-10-26 15:18:23 +03:00
|
|
|
expect(title).toBe('Redux DevTools');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should contain inspector monitor's component", async () => {
|
2021-09-06 21:07:02 +03:00
|
|
|
await delay(1000);
|
2021-08-27 19:08:40 +03:00
|
|
|
const val = await driver
|
2020-10-26 15:18:23 +03:00
|
|
|
.findElement(webdriver.By.xpath('//div[contains(@class, "inspector-")]'))
|
|
|
|
.getText();
|
2020-12-19 23:01:09 +03:00
|
|
|
expect(val).toBeDefined();
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should contain an empty actions list', async () => {
|
2021-08-27 19:08:40 +03:00
|
|
|
const val = await driver
|
2020-10-26 15:18:23 +03:00
|
|
|
.findElement(
|
2023-07-12 21:03:20 +03:00
|
|
|
webdriver.By.xpath('//div[contains(@class, "actionListRows-")]'),
|
2020-10-26 15:18:23 +03:00
|
|
|
)
|
|
|
|
.getText();
|
|
|
|
expect(val).toBe('');
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.keys(switchMonitorTests).forEach((description) =>
|
2023-07-12 21:03:20 +03:00
|
|
|
it(description, () => switchMonitorTests[description](driver)),
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
it('should get actions list', async () => {
|
|
|
|
const url = 'http://zalmoxisus.github.io/examples/router/';
|
2021-08-27 19:08:40 +03:00
|
|
|
await driver.executeScript(`window.open('${url}')`);
|
2020-10-26 15:18:23 +03:00
|
|
|
await delay(2000);
|
|
|
|
|
2021-08-27 19:08:40 +03:00
|
|
|
const tabs = await driver.getAllWindowHandles();
|
2020-10-26 15:18:23 +03:00
|
|
|
|
2021-08-27 19:08:40 +03:00
|
|
|
await driver.switchTo().window(tabs[1]);
|
|
|
|
expect(await driver.getCurrentUrl()).toMatch(url);
|
2020-10-26 15:18:23 +03:00
|
|
|
|
2021-08-27 19:08:40 +03:00
|
|
|
await driver.switchTo().window(tabs[0]);
|
2020-10-26 15:18:23 +03:00
|
|
|
|
2021-08-27 19:08:40 +03:00
|
|
|
const result = await driver.wait(
|
|
|
|
driver
|
2020-10-26 15:18:23 +03:00
|
|
|
.findElement(
|
2023-07-12 21:03:20 +03:00
|
|
|
webdriver.By.xpath('//div[contains(@class, "actionListRows-")]'),
|
2020-10-26 15:18:23 +03:00
|
|
|
)
|
|
|
|
.getText()
|
|
|
|
.then((val) => {
|
|
|
|
return actionsPattern.test(val);
|
|
|
|
}),
|
|
|
|
15000,
|
2023-07-12 21:03:20 +03:00
|
|
|
"it doesn't match actions pattern",
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|