mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
gui-tests-framework: added ScriptAction; ScriptCompileAction (not finished yet); ScriptRunnerAction
This commit is contained in:
@@ -47,5 +47,7 @@
|
||||
<orderEntry type="module" module-name="lang-impl" />
|
||||
<orderEntry type="library" name="JUnit4" level="project" />
|
||||
<orderEntry type="module" module-name="java-impl" />
|
||||
<orderEntry type="module" module-name="execution-impl" />
|
||||
<orderEntry type="module" module-name="compiler-openapi" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -2,5 +2,11 @@
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<uiDropperActions implementation="com.intellij.tests.gui.script.ScriptRecorder"/>
|
||||
</extensions>
|
||||
<actions>
|
||||
<action class="com.intellij.tests.gui.script.ScriptRunnerAction" id="ScriptRunnerAction" text="Script Runner Action"
|
||||
description="Add GUI tests to action list"/>
|
||||
<action class="com.intellij.tests.gui.script.ScriptCompileAction" id="ScriptCompileAction" text="Script Compile Action"
|
||||
description="Compile current script"/>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.intellij.ide.util.newProjectWizard.FrameworksTree;
|
||||
import com.intellij.ui.CheckboxTreeBase;
|
||||
import com.intellij.ui.treeStructure.Tree;
|
||||
import org.fest.swing.core.Robot;
|
||||
import org.fest.swing.edt.GuiActionRunner;
|
||||
import org.fest.swing.edt.GuiTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
@@ -66,7 +68,12 @@ public class FrameworksTreeFixture {
|
||||
if (frameworkSupportElement.getText().equals(frameworkName)) {
|
||||
//scroll tree to path
|
||||
final TreePath treePath = myFrameworksTree.getPathForRow(i);
|
||||
myFrameworksTree.scrollPathToVisible(treePath);
|
||||
GuiActionRunner.execute(new GuiTask() {
|
||||
@Override
|
||||
protected void executeInEDT() throws Throwable {
|
||||
myFrameworksTree.scrollPathToVisible(treePath);
|
||||
}
|
||||
});
|
||||
|
||||
final JCheckBox checkbox = frameworkSupportElement.getCheckbox();
|
||||
myRobot.click(checkbox);
|
||||
|
||||
@@ -22,13 +22,12 @@ import com.intellij.ide.RecentProjectsManager;
|
||||
import com.intellij.ide.actions.ShowSettingsUtilImpl;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.externalSystem.model.ExternalSystemException;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.FileContentQueue;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
@@ -65,7 +64,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.ide.impl.ProjectUtil.closeAndDispose;
|
||||
import static com.intellij.openapi.util.io.FileUtil.*;
|
||||
import static com.intellij.openapi.util.io.FileUtil.getRelativePath;
|
||||
import static com.intellij.openapi.util.io.FileUtil.toSystemDependentName;
|
||||
import static com.intellij.openapi.util.text.StringUtil.isNotEmpty;
|
||||
import static com.intellij.openapi.vfs.VfsUtilCore.urlToPath;
|
||||
import static com.intellij.tests.gui.framework.GuiTests.*;
|
||||
@@ -75,7 +75,8 @@ import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.fest.swing.edt.GuiActionRunner.execute;
|
||||
import static org.fest.swing.timing.Pause.pause;
|
||||
import static org.fest.util.Strings.quote;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Created by karashevich on 30/05/16.
|
||||
@@ -92,7 +93,7 @@ public class IdeFrameFixture extends ComponentFixture<IdeFrameFixture, IdeFrameI
|
||||
protected boolean isMatching(@NotNull IdeFrameImpl frame) {
|
||||
Project project = frame.getProject();
|
||||
if (projectPath == null && project != null) return true;
|
||||
if (project != null && toSystemIndependentName(projectPath.getPath()).equals(project.getBasePath())) {
|
||||
if (project != null && PathManager.getAbsolutePath(projectPath.getPath()).equals(PathManager.getAbsolutePath(project.getBasePath()))) {
|
||||
return projectName == null || projectName.equals(project.getName());
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -88,6 +88,19 @@ public abstract class GuiTestCase {
|
||||
return myTestName;
|
||||
}
|
||||
|
||||
|
||||
public void setRobot(Robot robot){
|
||||
myRobot = robot;
|
||||
}
|
||||
|
||||
public GuiTestCase(){
|
||||
|
||||
}
|
||||
|
||||
public GuiTestCase(Robot robot) {
|
||||
myRobot = robot;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (!canRunGuiTests()) {
|
||||
@@ -105,6 +118,7 @@ public abstract class GuiTestCase {
|
||||
setIdeSettings();
|
||||
setUpSdks();
|
||||
|
||||
|
||||
// There is a race condition between reloading the configuration file after file deletion detected and the serialization of IDEA model
|
||||
// we just customized so that modules can't be loaded correctly.
|
||||
// This is a hack to prevent StoreAwareProjectManager from doing any reloading during test.
|
||||
|
||||
@@ -187,6 +187,11 @@ public final class GuiTests {
|
||||
return jdkHome;
|
||||
}
|
||||
|
||||
public static void setupGitPath(){
|
||||
//GitVcsApplicationSettings settings = GitVcsApplicationSettings.getInstance();
|
||||
//settings.setPathToGit(GitExecutor.PathHolder.GIT_EXECUTABLE);
|
||||
}
|
||||
|
||||
public static void setUpSdks() {
|
||||
|
||||
String jdkHome = getSystemPropertyOrEnvironmentVariable(JDK_HOME_FOR_TESTS);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.tests.gui.script
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.tests.gui.framework.GuiTestCase
|
||||
import org.fest.swing.core.AdvancedRobot
|
||||
|
||||
/**
|
||||
* Created by jetbrains on 12/09/16.
|
||||
*/
|
||||
class ScriptAction(val scriptName: String) : AnAction("guiTest." + scriptName){
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent?) {
|
||||
|
||||
val myPackage = "com.intellij.tests.gui.test"
|
||||
val loadedClass = this.javaClass.classLoader.loadClass("${myPackage}.${scriptName}")
|
||||
val guiTest = loadedClass.newInstance() as GuiTestCase
|
||||
|
||||
//setting advanced robot
|
||||
guiTest.setRobot(AdvancedRobot())
|
||||
|
||||
val testsInClass = loadedClass.methods.filter { it.name.contains("test") }
|
||||
ApplicationManager.getApplication().executeOnPooledThread { testsInClass.get(0).invoke(guiTest) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.tests.gui.script
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.application.PathManager
|
||||
import com.intellij.openapi.compiler.CompilerManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
|
||||
/**
|
||||
* Created by @author Sergey Karashevich on 12/09/16.
|
||||
*/
|
||||
class ScriptCompileAction: AnAction(){
|
||||
|
||||
fun homePath() = PathManager.getHomePath()
|
||||
//we have to load idea project to compile kotlin files on the fly. Let's do it in a lazy manner.
|
||||
val project: Project? by lazy {
|
||||
ProjectManagerEx.getInstanceEx().loadProject("${homePath()}/idea.iml");
|
||||
}
|
||||
|
||||
val srcPath = "community/community-tests/src"
|
||||
val myPackage = "com.intellij.tests.gui.test"
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent?) {
|
||||
compileAndRun()
|
||||
}
|
||||
|
||||
fun compileAndRun() {
|
||||
val myPackagePath = myPackage.replace(".", "/")
|
||||
|
||||
val url = VfsUtil.pathToUrl("${homePath()}/${srcPath}/${myPackagePath}/CurrentTest.kt")
|
||||
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(url)
|
||||
|
||||
CompilerManager.getInstance(project).compile(arrayOf(virtualFile), { aborted, errors, warnings, compileContext ->
|
||||
if (!aborted) {
|
||||
print("Compilation done")
|
||||
ScriptAction("CurrentTest").actionPerformed(AnActionEvent.createFromDataContext("nothing", null, DataContext.EMPTY_CONTEXT))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.tests.gui.script
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionManager
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Created by jetbrains on 12/09/16.
|
||||
*/
|
||||
class ScriptRunnerAction() : AnAction(){
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent?) {
|
||||
val myPackage = "com.intellij.tests.gui.test"
|
||||
val packagePath = myPackage.replace(".", "/")
|
||||
val testFolder = this.javaClass.classLoader.getResource(packagePath)
|
||||
val testFiles = File(testFolder.file).listFiles().filter { !it.name.contains("$") } //remove inlined classes
|
||||
val actionManager = ActionManager.getInstance()
|
||||
|
||||
testFiles.forEach {
|
||||
val testName = it.name.substring(0, it.name.indexOf('.'))
|
||||
val genId = "guiTest." + testName
|
||||
val script = ScriptAction(testName)
|
||||
if (actionManager.getAction(genId) != null)
|
||||
actionManager.unregisterAction(genId)
|
||||
actionManager.registerAction(genId, script)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.tests.gui.test
|
||||
|
||||
import com.intellij.tests.gui.framework.GuiTestCase
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Created by jetbrains on 12/09/16.
|
||||
*/
|
||||
|
||||
class CurrentTest: GuiTestCase(){
|
||||
|
||||
@Test
|
||||
fun testMe() {
|
||||
val ideFrame = findIdeFrame()
|
||||
ideFrame.waitForBackgroundTasksToFinish()
|
||||
|
||||
ideFrame.editor.enterText("Hello!")
|
||||
}
|
||||
}
|
||||
@@ -493,7 +493,7 @@ public class PathManager {
|
||||
System.err.println(x);
|
||||
}
|
||||
|
||||
private static String getAbsolutePath(String path) {
|
||||
public static String getAbsolutePath(String path) {
|
||||
path = FileUtil.expandUserHome(path);
|
||||
return FileUtil.toCanonicalPath(new File(path).getAbsolutePath());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user