Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on UI-tests started #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
plugins {
id "org.jetbrains.intellij" version "0.4.21"
id 'jacoco'
id 'org.jetbrains.kotlin.jvm' version '1.3.71'
}

apply plugin: 'org.jetbrains.intellij'
Expand All @@ -34,6 +35,14 @@ targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
maven { url = "https://jetbrains.bintray.com/intellij-third-party-dependencies" }
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

intellij {
Expand All @@ -60,6 +69,9 @@ configurations {
fbContribJava6
}

def remoteRobotVersion = "0.9.35"
def fixturesVersion = "1.1.18"

dependencies {
implementation ('com.github.spotbugs:spotbugs:4.0.6') {
exclude group: 'xml-apis', module: 'xml-apis'
Expand All @@ -73,6 +85,10 @@ dependencies {
thirdPartyPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
thirdPartyPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1'
fbContribJava6 'com.mebigfatguy.fb-contrib:fb-contrib:6.2.1'
testImplementation("com.intellij.remoterobot:remote-robot:$remoteRobotVersion")
testImplementation("com.intellij.remoterobot:remote-fixtures:$fixturesVersion")
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
}

task copyGradleProperties(type: Copy) {
Expand Down Expand Up @@ -105,8 +121,17 @@ tasks.buildPlugin.dependsOn(copyThirdPartyPlugins)
tasks.jacocoTestReport.dependsOn(deleteThirdPartyPlugins)
tasks.jacocoTestCoverageVerification.dependsOn(deleteThirdPartyPlugins)

downloadRobotServerPlugin.version = remoteRobotVersion

runIdeForUiTests {
systemProperty "robot-server.port", "8082"
}

tasks.test.dependsOn(runIdeForUiTests)

test {
finalizedBy jacocoTestReport
useJUnitPlatform()
}

jacocoTestReport {
Expand All @@ -118,6 +143,8 @@ jacocoTestReport {
}
}

buildSearchableOptions.enabled = false

wrapper {
gradleVersion = '6.3'
}
44 changes: 44 additions & 0 deletions src/test/java/org/jetbrains/plugins/spotbugs/SayHelloJavaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2020 SpotBugs plugin contributors
*
* This file is part of IntelliJ SpotBugs plugin.
*
* IntelliJ SpotBugs plugin is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* IntelliJ SpotBugs plugin is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IntelliJ SpotBugs plugin.
* If not, see <http://www.gnu.org/licenses/>.
*/

package org.jetbrains.plugins.spotbugs;

import com.intellij.remoterobot.RemoteRobot;
import org.jetbrains.plugins.spotbugs.steps.JavaExampleSteps;
import org.jetbrains.plugins.spotbugs.utils.StepsLogger;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;


public class SayHelloJavaTest {
@BeforeAll
public static void initLogging() {
StepsLogger.init();
}

@Test
void checkSayHello() {
final RemoteRobot remoteRobot = new RemoteRobot("http://127.0.0.1:8082");

JavaExampleSteps javaExampleSteps = new JavaExampleSteps(remoteRobot);
javaExampleSteps.createNewCommandLineProject();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2020 SpotBugs plugin contributors
*
* This file is part of IntelliJ SpotBugs plugin.
*
* IntelliJ SpotBugs plugin is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* IntelliJ SpotBugs plugin is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IntelliJ SpotBugs plugin.
* If not, see <http://www.gnu.org/licenses/>.
*/

package org.jetbrains.plugins.spotbugs.pages;

import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.ComponentFixture;
import com.intellij.remoterobot.fixtures.FixtureName;
import org.jetbrains.annotations.NotNull;


@FixtureName(name = "Action Link")
public class ActionLinkFixture extends ComponentFixture {
public ActionLinkFixture(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
super(remoteRobot, remoteComponent);
}

public void click() {
runJs("const offset = component.getHeight()/2;\n" +
"robot.click(" +
"component, " +
"new Point(offset, offset), " +
"MouseButton.LEFT_BUTTON, 1);"
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2020 SpotBugs plugin contributors
*
* This file is part of IntelliJ SpotBugs plugin.
*
* IntelliJ SpotBugs plugin is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* IntelliJ SpotBugs plugin is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IntelliJ SpotBugs plugin.
* If not, see <http://www.gnu.org/licenses/>.
*/

package org.jetbrains.plugins.spotbugs.pages;

import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.ComponentFixture;
import com.intellij.remoterobot.fixtures.ContainerFixture;
import com.intellij.remoterobot.fixtures.DefaultXpath;
import com.intellij.remoterobot.fixtures.FixtureName;
import org.jetbrains.annotations.NotNull;

import static com.intellij.remoterobot.search.locators.Locators.byXpath;


@DefaultXpath(by = "FlatWelcomeFrame type", xpath = "//div[@class='FlatWelcomeFrame']")
@FixtureName(name = "Welcome Frame")
public class WelcomeFrameFixture extends ContainerFixture {
public WelcomeFrameFixture(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
super(remoteRobot, remoteComponent);
}

public ActionLinkFixture createNewProjectLink() {
return find(ActionLinkFixture.class, byXpath("//div[@text='Create New Project' and @class='ActionLink']"));
}

public ComponentFixture importProjectLink() {
return find(ComponentFixture.class, byXpath("//div[@text='Import Project' and @class='ActionLink']"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2020 SpotBugs plugin contributors
*
* This file is part of IntelliJ SpotBugs plugin.
*
* IntelliJ SpotBugs plugin is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* IntelliJ SpotBugs plugin is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IntelliJ SpotBugs plugin.
* If not, see <http://www.gnu.org/licenses/>.
*/

package org.jetbrains.plugins.spotbugs.steps;

import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.fixtures.ComponentFixture;
import com.intellij.remoterobot.utils.Keyboard;
import kotlin.Unit;
import org.jetbrains.plugins.spotbugs.pages.DialogFixture;
import org.jetbrains.plugins.spotbugs.pages.IdeaFrame;
import org.jetbrains.plugins.spotbugs.pages.WelcomeFrameFixture;

import java.awt.event.KeyEvent;
import java.time.Duration;

import static com.intellij.remoterobot.search.locators.Locators.byXpath;
import static com.intellij.remoterobot.stepsProcessing.StepWorkerKt.step;

public class JavaExampleSteps {
final private RemoteRobot remoteRobot;
final private Keyboard keyboard;

public JavaExampleSteps(RemoteRobot remoteRobot) {
this.remoteRobot = remoteRobot;
this.keyboard = new Keyboard(remoteRobot);
}

public void createNewCommandLineProject() {
step("Create New Command Line Project", () -> {
final WelcomeFrameFixture welcomeFrame = remoteRobot.find(WelcomeFrameFixture.class);
welcomeFrame.createNewProjectLink().click();

final DialogFixture newProjectDialog = welcomeFrame.find(DialogFixture.class, DialogFixture.byTitle("New Project"), Duration.ofSeconds(20));
newProjectDialog.findText("Java").click();
newProjectDialog.find(ComponentFixture.class,
byXpath("FrameworksTree", "//div[@class='FrameworksTree']"))
.findText("Kotlin/JVM")
.click();
keyboard.key(KeyEvent.VK_SPACE, Duration.ZERO);
newProjectDialog.button("Next").click();
newProjectDialog.button("Finish").click();
});
}

public void closeTipOfTheDay() {
step("Close Tip of the Day if it appears", () -> {
final IdeaFrame idea = remoteRobot.find(IdeaFrame.class);
idea.dumbAware(() -> {
try {
idea.find(DialogFixture.class, DialogFixture.byTitle("Tip of the Day")).button("Close").click();
} catch (Throwable ignore) {
}
return Unit.INSTANCE;
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2020 SpotBugs plugin contributors
*
* This file is part of IntelliJ SpotBugs plugin.
*
* IntelliJ SpotBugs plugin is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* IntelliJ SpotBugs plugin is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IntelliJ SpotBugs plugin.
* If not, see <http://www.gnu.org/licenses/>.
*/

package org.jetbrains.plugins.spotbugs.pages;

import com.intellij.remoterobot.RemoteRobot
import com.intellij.remoterobot.data.RemoteComponent
import com.intellij.remoterobot.fixtures.ComponentFixture
import com.intellij.remoterobot.fixtures.FixtureName
import com.intellij.remoterobot.search.locators.byXpath
import com.intellij.remoterobot.utils.waitFor

fun RemoteRobot.actionMenu(text: String): ActionMenuFixture {
val xpath = byXpath("text '$text'", "//div[@class='ActionMenu' and @text='$text']")
waitFor {
findAll<ActionMenuFixture>(xpath).isNotEmpty()
}
return findAll<ActionMenuFixture>(xpath).first()
}

fun RemoteRobot.actionMenuItem(text: String): ActionMenuItemFixture {
val xpath = byXpath("text '$text'", "//div[@class='ActionMenuItem' and @text='$text']")
waitFor {
findAll<ActionMenuItemFixture>(xpath).isNotEmpty()
}
return findAll<ActionMenuItemFixture>(xpath).first()
}

@FixtureName("ActionMenu")
class ActionMenuFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : ComponentFixture(remoteRobot, remoteComponent)

@FixtureName("ActionMenuItem")
class ActionMenuItemFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : ComponentFixture(remoteRobot, remoteComponent)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2020 SpotBugs plugin contributors
*
* This file is part of IntelliJ SpotBugs plugin.
*
* IntelliJ SpotBugs plugin is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* IntelliJ SpotBugs plugin is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IntelliJ SpotBugs plugin.
* If not, see <http://www.gnu.org/licenses/>.
*/

package org.jetbrains.plugins.spotbugs.pages;

import com.intellij.remoterobot.RemoteRobot
import com.intellij.remoterobot.data.RemoteComponent
import com.intellij.remoterobot.fixtures.CommonContainerFixture
import com.intellij.remoterobot.fixtures.ContainerFixture
import com.intellij.remoterobot.fixtures.FixtureName
import com.intellij.remoterobot.search.locators.byXpath
import com.intellij.remoterobot.stepsProcessing.step
import java.time.Duration

fun ContainerFixture.dialog(
title: String,
timeout: Duration = Duration.ofSeconds(20),
function: DialogFixture.() -> Unit = {}): DialogFixture = step("Search for dialog with title $title") {
find<DialogFixture>(DialogFixture.byTitle(title), timeout).apply(function)
}

@FixtureName("Dialog")
class DialogFixture(
remoteRobot: RemoteRobot,
remoteComponent: RemoteComponent) : CommonContainerFixture(remoteRobot, remoteComponent) {

companion object {
@JvmStatic
fun byTitle(title: String) = byXpath("title $title", "//div[@title='$title' and @class='MyDialog']")
}

val title: String
get() = callJs("component.getTitle();")
}
Loading