Testing UI of IntelliJ Plugins
by Paweł Lipski (GitHub: PawelLipski)
gradle runIdeForUiTest
P
Similar to good old `gradle runIde`...
..but an extra plugin is added to the IntelliJ instance:
P
Quick demo: runIdeForUiTests
P
Locators: byXpath
P
Locator loginToGitHubLocator = byXpath( "//div[@class='MainButton' and @text='Log in to GitHub']" ); ComponentFixture loginToGitHub = remoteRobot.find( ComponentFixture.class, loginToGitHubLocator );
runJs/callJs
P
// `robot` and `component` are available out of the box loginToGitHub.runJs( """ const offset = component.getHeight() / 2; robot.click(component, new Point(offset, offset), MouseButton.LEFT_BUTTON, 1); """ )
JavaScript or Java? Rhino
P
importClass(com.intellij.diagnostic.DebugLogManager);
importClass(java.util.Stream);
const logCategories = Stream.of( 'gitmachete.backend', 'gitmachete.frontend.actions', 'gitmachete.frontend.graph', 'gitmachete.frontend.ui' ).map(function (name) { return new DebugLogManager.Category(name,
DebugLogManager.DebugLogLevel.DEBUG); }).collect(Collectors.toList());
Keep state b/w runJs/callJs's
P
runJs("greeting = 'Hello from Idea'");
// ....
runJs("java.lang.System.out.println(greeting)");
// WHOOPS the variables aren't kept between invocations
Keep state b/w runJs/callJs's
P
runJs("global.put('greeting', 'Hello from Idea')") // .... assert(callJs<String>("global.get('greeting')") == "Hello from Idea")
How to run in CI?
P
Problem: there's no physical display available
to the VMs/Docker containers running in the CI...
Xvfb
P
Xvfb is an X server that can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory.
Note that in X-speak, server corresponds to a display,
while client corresponds to an application
(unlike with e.g. remote desktops!)
xvfb-run
P
# Debian-like systems:
$ apt-get install libx11-6 libxrender1 libxtst6 xauth xvfb
xvfb-run
P
$ xvfb-run pstree ....
├─gnome-terminal───bash───xvfb-run─┬─Xvfb───8*[{Xvfb}] │ └─pstree
....
P
Run the given version of IntelliJ programatically, directly from test code
(rather than via a separate
`gradle runIdeForUiTests` invocation)
P
Quick demo:
run an actual UI test
P
./scripts/run-ui-tests 2021.1.2 discoverBranchLayout
Questions?
P
Testing UI of IntelliJ Plugins
By plipski
Testing UI of IntelliJ Plugins
- 4,956