gui-tests-framework: change start IdeTestApplication from GuiTestCase method to a proper annotation; cleanup

This commit is contained in:
Sergey Karashevich
2016-10-09 17:59:25 +03:00
parent 01428b8c31
commit a89512ac83
13 changed files with 19 additions and 456 deletions
@@ -343,6 +343,4 @@ public abstract class GuiTestBase {
});
}
public abstract Class<? extends IdeTestApplication> getIdeTestApplicationClass();
}
@@ -36,7 +36,6 @@ import java.awt.*;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -60,22 +59,7 @@ public class GuiTestRunner extends BlockJUnit4ClassRunner {
Class<?> guiTestCaseClass = testClass.getSuperclass();
//check test extends GuiTestBase
guiTestCaseClass.isInstance(GuiTestBase.class);
try {
myIdeTestApplicationClass = (Class<? extends IdeTestApplication>)guiTestCaseClass.getMethod("getIdeTestApplicationClass")
.invoke(guiTestCaseClass.newInstance());
}
catch (NoSuchMethodException e) {
e.printStackTrace();
}
catch (InstantiationException e) {
e.printStackTrace();
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
myIdeTestApplicationClass = guiTestCaseClass.getAnnotation(TestWithIde.class).value();
myScreenshotTaker = canRunGuiTests() ? new ScreenshotTaker() : null;
@@ -1,49 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testGuiFramework.framework
import com.intellij.testGuiFramework.impl.GuiTestCase
import com.intellij.ui.components.JBList
import org.fest.swing.core.Robot
import org.fest.swing.fixture.JListFixture
import org.fest.swing.timing.Condition
import org.fest.swing.timing.Pause
import java.awt.Container
/**
We presume that IDEA is already started, shows "Welcome dialog" and we could create a new project
!!UNFINISHED!!
**/
fun GuiTestCase.createNewProject(): com.intellij.testGuiFramework.fixtures.WelcomeFrameFixture {
return findWelcomeFrame().createNewProject()
}
fun pause(time: Long, root: Robot) {
Pause.pause(object : Condition("Wait for user actions") {
override fun test(): Boolean {
return false
}
}, time)
}
fun clickListItem(itemName: String, robot: Robot, parentContainer: Container) {
val listFixture = JListFixture(robot, robot.finder().findByType(parentContainer, JBList::class.java, true))
listFixture.clickItem(itemName)
}
@@ -13,21 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testGuiFramework.tests
package com.intellij.testGuiFramework.framework;
import com.intellij.testGuiFramework.impl.GuiTestCase
import org.junit.Test
import java.lang.annotation.*;
/**
* @author Sergey Karashevich
*/
class CurrentTest: GuiTestCase(){
@Test
fun testMe() {
val ideFrame = findIdeFrame()
ideFrame.waitForBackgroundTasksToFinish()
ideFrame.editor.enterText("Hello!")
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface TestWithIde {
/**
* @return a IdeTestApplication class (must have a getInstance() method that runs apropriate IDE)
*/
Class<? extends IdeTestApplication> value();
}
@@ -16,7 +16,7 @@
package com.intellij.testGuiFramework.impl;
import com.intellij.testGuiFramework.framework.GuiTestBase;
import com.intellij.testGuiFramework.framework.IdeTestApplication;
import com.intellij.testGuiFramework.framework.TestWithIde;
import com.intellij.util.net.HttpConfigurable;
import org.fest.swing.core.FastRobot;
@@ -26,6 +26,7 @@ import static com.intellij.testGuiFramework.framework.GuiTestUtil.setUpSdks;
/**
* @author Sergey Karashevich
*/
@TestWithIde(IdeaGuiTestApp.class)
public class GuiTestCase extends GuiTestBase {
public GuiTestCase() {
@@ -43,12 +44,6 @@ public class GuiTestCase extends GuiTestBase {
setUpSdks();
}
@Override
public Class<? extends IdeTestApplication> getIdeTestApplicationClass() {
return IdeTestApplicationImpl.class;
}
private static void setIdeSettings() {
// Clear HTTP proxy settings, in case a test changed them.
HttpConfigurable ideSettings = HttpConfigurable.getInstance();
@@ -49,7 +49,7 @@ import static com.intellij.util.ui.UIUtil.initDefaultLAF;
import static org.fest.reflect.core.Reflection.method;
import static org.junit.Assert.assertNotNull;
public class IdeTestApplicationImpl extends IdeTestApplication implements Disposable {
public class IdeaGuiTestApp extends IdeTestApplication implements Disposable {
private static final Logger LOG = Logger.getInstance(IdeTestApplication.class);
private static final String PROPERTY_IGNORE_CLASSPATH = "ignore.classpath";
private static final String PROPERTY_ALLOW_BOOTSTRAP_RESOURCES = "idea.allow.bootstrap.resources";
@@ -69,7 +69,7 @@ public class IdeTestApplicationImpl extends IdeTestApplication implements Dispos
System.setProperty("idea.test.guimode", "true");
if (!isLoaded()) {
ourInstance = new IdeTestApplicationImpl();
ourInstance = new IdeaGuiTestApp();
recreateDirectory(configDirPath);
File newProjectsRootDirPath = getProjectCreationDirPath();
@@ -96,7 +96,7 @@ public class IdeTestApplicationImpl extends IdeTestApplication implements Dispos
ensureExists(path);
}
private IdeTestApplicationImpl() throws Exception {
private IdeaGuiTestApp() throws Exception {
String[] args = EMPTY_STRING_ARRAY;
LOG.assertTrue(ourInstance == null, "Only one instance allowed.");
@@ -26,6 +26,7 @@ import com.intellij.ui.EditorComboBox
import org.fest.swing.edt.GuiActionRunner
import org.fest.swing.edt.GuiTask
import org.fest.swing.fixture.DialogFixture
import org.junit.Ignore
import org.junit.Test
/**
@@ -33,7 +34,7 @@ import org.junit.Test
*/
class GitGuiTest : GuiTestCase() {
@Test
@Test @Ignore
fun testGitImport(){
val vcsName = "Git"
val gitApp = "path_to_git_repo"
@@ -60,7 +61,6 @@ class GitGuiTest : GuiTestCase() {
with (dialog1) {
GuiTestUtil.findAndClickButton(this, "Next")
val textField = GuiTestUtil.findTextField(myRobot, "Project name:").click()
// textField.setText("test-project")
GuiTestUtil.findAndClickButton(this, "Next")
GuiTestUtil.findAndClickButton(this, "Next")
GuiTestUtil.findAndClickButton(this, "Next") //libraries
@@ -1,101 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testGuiFramework.tests;
import com.intellij.dvcs.ui.CloneDvcsDialog;
import com.intellij.dvcs.ui.DvcsBundle;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.testGuiFramework.fixtures.*;
import com.intellij.testGuiFramework.impl.GuiTestCase;
import com.intellij.ui.EditorComboBox;
import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.edt.GuiTask;
import org.junit.Ignore;
import org.junit.Test;
import static com.intellij.testGuiFramework.framework.GuiTestUtil.findAndClickButton;
/**
* @author Sergey Karashevich
*/
public class JavaGitGuiTest extends GuiTestCase {
@Ignore
@Test
public void testGitImport(){
String gitPath = "https://github.com/karashevich/test.git";
//wait welcome frame
//get welcome frame
WelcomeFrameFixture welcomeFrameFixture = WelcomeFrameFixture.find(myRobot);
//click ActionLink "Check out from Version Control"
welcomeFrameFixture.checkoutFrom();
//click ListPopup menu item "Git"
String vcsName = "Git";
JBListPopupFixture.findListPopup(myRobot).invokeAction(vcsName);
//find new dialog "Clone Repository"
DialogFixture dialogFixture = new DialogFixture(myRobot, IdeaDialogFixture.find(myRobot, CloneDvcsDialog.class).dialog);
//find EditorComboBox near label "Git Repository URL:"
String message = DvcsBundle.message("clone.repository.url", vcsName);
EditorComboBox editorComboBox = myRobot.finder().findByLabel(dialogFixture.target(), message, EditorComboBox.class);
//enter gitPath
GuiActionRunner.execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
editorComboBox.setText(gitPath);
}
});
//click button "Clone"
findAndClickButton(dialogFixture, DvcsBundle.message("clone.button"));
//find message with title "Checkout From Version Control"
//click "Yes"
MessagesFixture.findByTitle(myRobot, welcomeFrameFixture.target(), VcsBundle.message("checkout.title")).clickYes();
//find new dialog "Import Project"
DialogFixture importProjectFixture = DialogFixture.find(myRobot, "Import Project");
//click "Next"
findAndClickButton(importProjectFixture, "Next");
//click "Next"
findAndClickButton(importProjectFixture, "Next");
//click "Next"
findAndClickButton(importProjectFixture, "Next");
//click "Next"
findAndClickButton(importProjectFixture, "Next");
//click "Next"
findAndClickButton(importProjectFixture, "Next");
//click "Next"
findAndClickButton(importProjectFixture, "Next");
//find message with title "No SDK Specified"
//click "Ok"
MessagesFixture.findByTitle(myRobot, welcomeFrameFixture.target(), IdeBundle.message("title.no.jdk.specified")).clickOk();
//click "Finish"
findAndClickButton(importProjectFixture, "Finish");
//wait ideFrame
IdeFrameFixture ideFrame = findIdeFrame();
//wait background processes (indexing)
ideFrame.waitForBackgroundTasksToFinish();
//check java class "src/Test.java"
//open Test.java in editor
String testJavaPath = "src/Test.java";
EditorFixture editor = ideFrame.getEditor();
editor.open(testJavaPath);
}
}
@@ -1,87 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testGuiFramework.tests
import com.intellij.testGuiFramework.fixtures.DialogFixtures.CreateDialogFixture
import com.intellij.testGuiFramework.fixtures.EditorFixture
import com.intellij.testGuiFramework.fixtures.JBPopupFixture
import com.intellij.testGuiFramework.framework.clickListItem
import com.intellij.testGuiFramework.framework.createNewProject
import com.intellij.testGuiFramework.impl.GuiTestCase
import org.junit.Ignore
import org.junit.Test
import java.io.File
import javax.swing.text.JTextComponent
/**
* @author Sergey Karashevich
*/
class JavaProjectTest: GuiTestCase() {
@Test
@Ignore
fun testJavaProject(){
var locationFile: File? = null
val projectName = "smoke-test"
createNewProject()
val newProjectWizard = findNewProjectWizard()
with(newProjectWizard){
setupJdk()
// selectProjectType("Java")
clickListItem("Java", robot(), this.target())
selectFramework("JavaEE Persistence")
clickNext()
setProjectName(projectName);
locationFile = locationInFileSystem
clickFinish()
}
requireNotNull(locationFile) {
"Unable to determine location for \"$projectName\" project"
}
val ideFrame = findIdeFrame(projectName, locationFile!!)
with(ideFrame){
val paneFixture = projectView.selectProjectPane()
paneFixture.selectByPath(projectName, "src", "META-INF", "persistence.xml").doubleClick(robot())
val node = paneFixture.selectByPath(projectName, "src")
node.invokeContextMenu(robot())
val contextMenu = JBPopupFixture.findContextMenu(robot())
waitForBackgroundTasksToFinish()
with(contextMenu) {
assertContainsAction("Cut")
invokeAction("New", "Java Class")
}
val newDialog = CreateDialogFixture.find(robot())
with(newDialog) {
val jTextComponent = robot().finder().findByLabel("Name:", JTextComponent::class.java)
jTextComponent.setText("Test")
clickOK()
}
with(editor) {
invokeAction(EditorFixture.EditorAction.COMPLETE_CURRENT_STATEMENT)
enterText("psvm")
invokeAction(EditorFixture.EditorAction.TAB)
}
waitForBackgroundTasksToFinish()
}
}
}
@@ -1,93 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testGuiFramework.tests;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.testGuiFramework.fixtures.ProjectViewFixture;
import com.intellij.testGuiFramework.fixtures.newProjectWizard.NewProjectWizardFixture;
import com.intellij.testGuiFramework.framework.GuiTestUtil;
import com.intellij.testGuiFramework.framework.IdeGuiTest;
import com.intellij.testGuiFramework.impl.GuiTestCase;
import org.junit.Ignore;
import org.junit.Test;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import static com.intellij.testGuiFramework.framework.GuiTestUtil.getSystemJdk;
/**
* @author Sergey Karashevich
*/
public class NewProjectTest extends GuiTestCase {
//Should run with main_idea_tests module classpath
@Test @IdeGuiTest
@Ignore
public void testNewProject() throws IOException, InterruptedException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
Date date = new Date();
String projectName = "smoke-test-project-" + dateFormat.format(date);
findWelcomeFrame().createNewProject();
NewProjectWizardFixture newProjectWizard = findNewProjectWizard();
//check Project SDK is not Empty
setupJdkIfNeeded(newProjectWizard);
//select project type and framework
newProjectWizard.
selectProjectType("Java").
selectFramework("JavaEE Persistence");
newProjectWizard.clickNext();
newProjectWizard.setProjectName(projectName);
final File locationInFileSystem = newProjectWizard.getLocationInFileSystem();
newProjectWizard.clickFinish();
myProjectFrame = findIdeFrame(projectName, locationInFileSystem);
final ProjectViewFixture projectView = myProjectFrame.getProjectView();
final ProjectViewFixture.PaneFixture paneFixture = projectView.selectProjectPane();
paneFixture.selectByPath(projectName, "src", "META-INF", "persistence.xml");
Thread.sleep(10000);
}
private void setupJdkIfNeeded(NewProjectWizardFixture newProjectWizard) {
if (newProjectWizard.isJdkEmpty()) {
JButton newButton = GuiTestUtil.findButton(newProjectWizard,
GuiTestUtil.adduction(ApplicationBundle.message("button.new")),
myRobot);
myRobot.click(newButton);
File javaSdkPath = new File(getSystemJdk());
String sdkType = GuiTestUtil.adduction(ProjectBundle.message("sdk.java.name"));
GuiTestUtil.clickPopupMenuItem(sdkType, newButton, myRobot);
newProjectWizard.selectSdkPath(javaSdkPath, sdkType);
}
}
}
@@ -1,40 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testGuiFramework.tests
import com.intellij.testGuiFramework.fixtures.WelcomeFrameFixture
import com.intellij.testGuiFramework.framework.createNewProject
import com.intellij.testGuiFramework.impl.GuiTestCase
import org.junit.Assert
import org.junit.Test
/**
* @author Sergey Karashevich
*/
class ShortGuiTest: GuiTestCase() {
@Test
fun testJavaProject(){
val createNewProject = createNewProject()
val newProjectWizard = findNewProjectWizard()
with(newProjectWizard) {
clickCancel()
}
val find = WelcomeFrameFixture.find(myRobot)
Assert.assertNotNull(find)
}
}
@@ -1,32 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testGuiFramework.tests
import com.intellij.testGuiFramework.framework.IdeGuiTest
import com.intellij.testGuiFramework.impl.GuiTestCase
import org.junit.Test
/**
* @author Sergey Karashevich
*/
class SimpleApplicationImportTest: GuiTestCase() {
@Test @IdeGuiTest
fun testSimpleApplication(){
val app = importSimpleApplication()
app.waitForBackgroundTasksToFinish()
}
}
@@ -23,13 +23,11 @@ import com.intellij.testGuiFramework.framework.GuiTestUtil;
import com.intellij.testGuiFramework.impl.GuiTestCase;
import git4idea.i18n.GitBundle;
import org.fest.swing.core.FastRobot;
import org.fest.swing.timing.Pause;
import org.junit.Test;
import java.awt.event.KeyEvent;
import java.io.IOException;
import static com.intellij.testGuiFramework.framework.GuiTestUtil.SHORT_TIMEOUT;
import static com.intellij.testGuiFramework.matcher.TitleMatcher.withTitleMatcher;
/**
@@ -67,20 +65,11 @@ public class SimpleGitTest extends GuiTestCase {
GuiTestUtil.invokeActionViaShortcut(myRobot, "meta K");
DialogFixture commitDialogFixture = DialogFixture.find(myRobot, VcsBundle.message("commit.dialog.title"));
//EditorTextField editorTextField = myRobot.finder().findByType(commitDialogFixture.target(), EditorTextField.class);
//editorTextField.getDocument().setText("");
myRobot.enterText("initial commit");
GuiTestUtil.findAndClickButton(commitDialogFixture, "Commit");
MessagesFixture.findByTitle(myRobot, commitDialogFixture.target(), VcsBundle.message("code.smells.error.messages.tab.name"))
.click("Commit");
Pause.pause(SHORT_TIMEOUT.duration());
//create file in project src/Second.java
//init git
//add Second.java to git
//commit
}
catch (IOException e) {
e.printStackTrace();