2020-10-26 15:18:23 +03:00
|
|
|
import { resolve } from 'path';
|
|
|
|
import webdriver from 'selenium-webdriver';
|
2020-11-17 03:57:35 +03:00
|
|
|
import chromedriver from 'chromedriver';
|
2020-10-26 15:18:23 +03:00
|
|
|
import { switchMonitorTests, delay } from '../utils/e2e';
|
|
|
|
|
|
|
|
const port = 9515;
|
2021-06-20 06:08:00 +03:00
|
|
|
const path = resolve(__dirname, '..', '..', 'build', 'extension');
|
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 () {
|
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);
|
|
|
|
this.driver = new webdriver.Builder()
|
|
|
|
.usingServer(`http://localhost:${port}`)
|
|
|
|
.withCapabilities({
|
|
|
|
chromeOptions: {
|
|
|
|
args: [`load-extension=${path}`],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.forBrowser('chrome')
|
|
|
|
.build();
|
|
|
|
});
|
2020-12-19 23:01:09 +03:00
|
|
|
afterAll(async () => {
|
2020-10-26 15:18:23 +03:00
|
|
|
await this.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 () => {
|
|
|
|
await this.driver.get(`chrome-extension://${extensionId}/window.html#left`);
|
|
|
|
const url = await this.driver.getCurrentUrl();
|
|
|
|
expect(url).toBe(`chrome-extension://${extensionId}/window.html#left`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should match document title', async () => {
|
|
|
|
const title = await this.driver.getTitle();
|
|
|
|
expect(title).toBe('Redux DevTools');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should contain inspector monitor's component", async () => {
|
2020-12-19 23:01:09 +03:00
|
|
|
const val = await this.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 () => {
|
|
|
|
const val = await this.driver
|
|
|
|
.findElement(
|
|
|
|
webdriver.By.xpath('//div[contains(@class, "actionListRows-")]')
|
|
|
|
)
|
|
|
|
.getText();
|
|
|
|
expect(val).toBe('');
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.keys(switchMonitorTests).forEach((description) =>
|
|
|
|
it(description, switchMonitorTests[description].bind(this))
|
|
|
|
);
|
|
|
|
|
|
|
|
it('should get actions list', async () => {
|
|
|
|
const url = 'http://zalmoxisus.github.io/examples/router/';
|
|
|
|
await this.driver.executeScript(`window.open('${url}')`);
|
|
|
|
await delay(2000);
|
|
|
|
|
|
|
|
const tabs = await this.driver.getAllWindowHandles();
|
|
|
|
|
|
|
|
await this.driver.switchTo().window(tabs[1]);
|
|
|
|
expect(await this.driver.getCurrentUrl()).toMatch(url);
|
|
|
|
await this.driver.manage().timeouts().pageLoadTimeout(5000);
|
|
|
|
|
|
|
|
await this.driver.switchTo().window(tabs[0]);
|
|
|
|
|
|
|
|
const result = await this.driver.wait(
|
|
|
|
this.driver
|
|
|
|
.findElement(
|
|
|
|
webdriver.By.xpath('//div[contains(@class, "actionListRows-")]')
|
|
|
|
)
|
|
|
|
.getText()
|
|
|
|
.then((val) => {
|
|
|
|
return actionsPattern.test(val);
|
|
|
|
}),
|
|
|
|
15000,
|
|
|
|
"it doesn't match actions pattern"
|
|
|
|
);
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|