2020-10-26 15:18:23 +03:00
|
|
|
import { join } from 'path';
|
|
|
|
import webdriver from 'selenium-webdriver';
|
|
|
|
import electronPath from 'electron';
|
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-06 22:04:43 +03:00
|
|
|
const devPanelPath =
|
|
|
|
'chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/window.html';
|
2020-10-26 15:18:23 +03:00
|
|
|
|
|
|
|
describe('DevTools panel for Electron', 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(1000);
|
|
|
|
this.driver = new webdriver.Builder()
|
|
|
|
.usingServer(`http://localhost:${port}`)
|
|
|
|
.withCapabilities({
|
|
|
|
chromeOptions: {
|
|
|
|
binary: electronPath,
|
|
|
|
args: [`app=${join(__dirname, 'fixture')}`],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.forBrowser('electron')
|
|
|
|
.build();
|
|
|
|
await this.driver.manage().timeouts().setScriptTimeout(10000);
|
|
|
|
});
|
|
|
|
|
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 Redux DevTools tab', async () => {
|
2021-06-06 22:04:43 +03:00
|
|
|
if (!(await this.driver.getCurrentUrl()).startsWith('devtools')) {
|
|
|
|
const originalWindow = await this.driver.getWindowHandle();
|
|
|
|
const windows = await this.driver.getAllWindowHandles();
|
|
|
|
for (const window of windows) {
|
|
|
|
if (window === originalWindow) continue;
|
|
|
|
await this.driver.switchTo().window(window);
|
|
|
|
if ((await this.driver.getCurrentUrl()).startsWith('devtools')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-26 15:18:23 +03:00
|
|
|
expect(await this.driver.getCurrentUrl()).toMatch(
|
2021-06-06 22:04:43 +03:00
|
|
|
/devtools:\/\/devtools\/bundled\/devtools_app.html/
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
await this.driver.manage().timeouts().pageLoadTimeout(5000);
|
|
|
|
|
|
|
|
const id = await this.driver.executeAsyncScript(function (callback) {
|
|
|
|
let attempts = 5;
|
|
|
|
function showReduxPanel() {
|
|
|
|
if (attempts === 0) {
|
|
|
|
return callback('Redux panel not found');
|
|
|
|
}
|
2021-06-06 22:04:43 +03:00
|
|
|
if (UI.inspectorView) {
|
|
|
|
const tabs = UI.inspectorView._tabbedPane._tabs;
|
|
|
|
const idList = tabs.map((tab) => tab.id);
|
|
|
|
const reduxPanelId =
|
|
|
|
'chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljdRedux';
|
|
|
|
if (idList.indexOf(reduxPanelId) !== -1) {
|
|
|
|
UI.inspectorView.showPanel(reduxPanelId);
|
|
|
|
return callback(reduxPanelId);
|
|
|
|
}
|
2020-10-26 15:18:23 +03:00
|
|
|
}
|
|
|
|
attempts--;
|
|
|
|
setTimeout(showReduxPanel, 500);
|
|
|
|
}
|
|
|
|
showReduxPanel();
|
|
|
|
});
|
2021-06-06 22:04:43 +03:00
|
|
|
expect(id).toBe('chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljdRedux');
|
2020-10-26 15:18:23 +03:00
|
|
|
|
|
|
|
const className = await this.driver
|
|
|
|
.findElement(webdriver.By.className(id))
|
|
|
|
.getAttribute('class');
|
2020-12-19 23:01:09 +03:00
|
|
|
expect(className).not.toMatch(/hidden/); // not hidden
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should have Redux DevTools UI on current tab', async () => {
|
|
|
|
await this.driver
|
|
|
|
.switchTo()
|
|
|
|
.frame(
|
|
|
|
this.driver.findElement(
|
|
|
|
webdriver.By.xpath(`//iframe[@src='${devPanelPath}']`)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
await delay(1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should contain INIT action', async () => {
|
|
|
|
const element = await this.driver.wait(
|
|
|
|
webdriver.until.elementLocated(
|
|
|
|
webdriver.By.xpath('//div[contains(@class, "actionListRows-")]')
|
|
|
|
),
|
|
|
|
5000,
|
|
|
|
'Element not found'
|
|
|
|
);
|
|
|
|
const val = await element.getText();
|
|
|
|
expect(val).toMatch(/@@INIT/);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should contain Inspector monitor's component", async () => {
|
|
|
|
const val = await this.driver
|
|
|
|
.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
|
|
|
});
|
|
|
|
|
|
|
|
Object.keys(switchMonitorTests).forEach((description) =>
|
|
|
|
it(description, switchMonitorTests[description].bind(this))
|
|
|
|
);
|
|
|
|
|
|
|
|
/* it('should be no logs in console of main window', async () => {
|
|
|
|
const handles = await this.driver.getAllWindowHandles();
|
|
|
|
await this.driver.switchTo().window(handles[1]); // Change to main window
|
|
|
|
|
|
|
|
expect(await this.driver.getTitle()).toBe('Electron Test');
|
|
|
|
|
|
|
|
const logs = await this.driver.manage().logs().get(webdriver.logging.Type.BROWSER);
|
|
|
|
expect(logs).toEqual([]);
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
});
|