2020-10-26 15:18:23 +03:00
|
|
|
import { join } from 'path';
|
|
|
|
import webdriver from 'selenium-webdriver';
|
2021-10-21 17:15:09 +03:00
|
|
|
import chrome from 'selenium-webdriver/chrome';
|
2020-10-26 15:18:23 +03:00
|
|
|
import electronPath from 'electron';
|
2023-08-30 05:06:16 +03:00
|
|
|
import chromedriver from 'chromedriver';
|
2020-10-26 15:18:23 +03:00
|
|
|
import { switchMonitorTests, delay } from '../utils/e2e';
|
|
|
|
|
2021-06-06 22:04:43 +03:00
|
|
|
const devPanelPath =
|
2024-09-04 04:47:16 +03:00
|
|
|
'chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/devpanel.html';
|
2020-10-26 15:18:23 +03:00
|
|
|
|
|
|
|
describe('DevTools panel for Electron', 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(1000);
|
2021-08-27 19:08:40 +03:00
|
|
|
driver = new webdriver.Builder()
|
2023-12-08 03:15:18 +03:00
|
|
|
.usingServer('http://localhost:9515')
|
2021-10-21 17:15:09 +03:00
|
|
|
.setChromeOptions(
|
|
|
|
new chrome.Options()
|
|
|
|
.setChromeBinaryPath(electronPath)
|
2023-07-12 21:03:20 +03:00
|
|
|
.addArguments(`app=${join(__dirname, 'fixture')}`),
|
2021-10-21 17:15:09 +03:00
|
|
|
)
|
|
|
|
.forBrowser('chrome')
|
2020-10-26 15:18:23 +03:00
|
|
|
.build();
|
|
|
|
});
|
|
|
|
|
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 Redux DevTools tab', async () => {
|
2021-08-27 19:08:40 +03:00
|
|
|
if (!(await driver.getCurrentUrl()).startsWith('devtools')) {
|
|
|
|
const originalWindow = await driver.getWindowHandle();
|
|
|
|
const windows = await driver.getAllWindowHandles();
|
2021-06-06 22:04:43 +03:00
|
|
|
for (const window of windows) {
|
|
|
|
if (window === originalWindow) continue;
|
2021-08-27 19:08:40 +03:00
|
|
|
await driver.switchTo().window(window);
|
|
|
|
if ((await driver.getCurrentUrl()).startsWith('devtools')) {
|
2021-06-06 22:04:43 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-27 19:08:40 +03:00
|
|
|
expect(await driver.getCurrentUrl()).toMatch(
|
2023-07-12 21:03:20 +03:00
|
|
|
/devtools:\/\/devtools\/bundled\/devtools_app.html/,
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
|
2021-08-27 19:08:40 +03:00
|
|
|
const id = await driver.executeAsyncScript(function (callback) {
|
2020-10-26 15:18:23 +03:00
|
|
|
let attempts = 5;
|
|
|
|
function showReduxPanel() {
|
|
|
|
if (attempts === 0) {
|
|
|
|
return callback('Redux panel not found');
|
|
|
|
}
|
2024-06-10 05:48:52 +03:00
|
|
|
if (EUI.InspectorView) {
|
|
|
|
const instance = EUI.InspectorView.InspectorView.instance();
|
|
|
|
const tabs = instance.tabbedPane.tabs;
|
2021-06-06 22:04:43 +03:00
|
|
|
const idList = tabs.map((tab) => tab.id);
|
|
|
|
const reduxPanelId =
|
|
|
|
'chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljdRedux';
|
|
|
|
if (idList.indexOf(reduxPanelId) !== -1) {
|
2024-06-10 05:48:52 +03:00
|
|
|
instance.showPanel(reduxPanelId);
|
2021-06-06 22:04:43 +03:00
|
|
|
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
|
|
|
|
2021-08-27 19:08:40 +03:00
|
|
|
const className = await driver
|
2020-10-26 15:18:23 +03:00
|
|
|
.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
|
|
|
});
|
|
|
|
|
2024-09-04 04:47:16 +03:00
|
|
|
it('should have Redux DevTools UI on current tab', async () => {
|
2021-08-27 19:08:40 +03:00
|
|
|
await driver
|
2020-10-26 15:18:23 +03:00
|
|
|
.switchTo()
|
|
|
|
.frame(
|
2021-08-27 19:08:40 +03:00
|
|
|
driver.findElement(
|
2023-07-12 21:03:20 +03:00
|
|
|
webdriver.By.xpath(`//iframe[@src='${devPanelPath}']`),
|
|
|
|
),
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
await delay(1000);
|
|
|
|
});
|
|
|
|
|
2024-09-04 04:47:16 +03:00
|
|
|
it('should contain INIT action', async () => {
|
2021-08-27 19:08:40 +03:00
|
|
|
const element = await driver.wait(
|
2020-10-26 15:18:23 +03:00
|
|
|
webdriver.until.elementLocated(
|
2023-12-12 07:02:35 +03:00
|
|
|
webdriver.By.xpath('//div[@data-testid="actionListRows"]'),
|
2020-10-26 15:18:23 +03:00
|
|
|
),
|
|
|
|
5000,
|
2023-07-12 21:03:20 +03:00
|
|
|
'Element not found',
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
const val = await element.getText();
|
|
|
|
expect(val).toMatch(/@@INIT/);
|
|
|
|
});
|
|
|
|
|
2024-09-04 04:47:16 +03:00
|
|
|
it("should contain Inspector monitor's component", async () => {
|
2021-08-27 19:08:40 +03:00
|
|
|
const val = await driver
|
2023-12-12 07:02:35 +03:00
|
|
|
.findElement(webdriver.By.xpath('//div[@data-testid="inspector"]'))
|
2020-10-26 15:18:23 +03:00
|
|
|
.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) =>
|
2024-09-04 04:47:16 +03:00
|
|
|
it(description, () => switchMonitorTests[description](driver)),
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
/* it('should be no logs in console of main window', async () => {
|
2021-08-27 19:08:40 +03:00
|
|
|
const handles = await driver.getAllWindowHandles();
|
|
|
|
await driver.switchTo().window(handles[1]); // Change to main window
|
2020-10-26 15:18:23 +03:00
|
|
|
|
2021-08-27 19:08:40 +03:00
|
|
|
expect(await driver.getTitle()).toBe('Electron Test');
|
2020-10-26 15:18:23 +03:00
|
|
|
|
2021-08-27 19:08:40 +03:00
|
|
|
const logs = await driver.manage().logs().get(webdriver.logging.Type.BROWSER);
|
2020-10-26 15:18:23 +03:00
|
|
|
expect(logs).toEqual([]);
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
});
|