-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new automated UI test for Arquillia Cruiser View
- Loading branch information
Showing
7 changed files
with
329 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...lian.reddeer/src/org/jboss/tools/arquillian/ui/bot/reddeer/view/ArquilliaCruiserView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.jboss.tools.arquillian.ui.bot.reddeer.view; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.jboss.reddeer.swt.api.Tree; | ||
import org.jboss.reddeer.swt.api.TreeItem; | ||
import org.jboss.reddeer.swt.impl.tree.DefaultTree; | ||
import org.jboss.reddeer.swt.impl.tree.DefaultTreeItem; | ||
import org.jboss.reddeer.workbench.impl.view.WorkbenchView; | ||
|
||
/** | ||
* Represents the Build List view - to support Mylyn automated tests. | ||
* | ||
* @author ldimaggi | ||
* | ||
*/ | ||
public class ArquilliaCruiserView extends WorkbenchView { | ||
|
||
protected final static Logger log = Logger.getLogger(ArquilliaCruiserView.class); | ||
|
||
public static final String TITLE = "Arquillia Cruiser"; | ||
|
||
public ArquilliaCruiserView() { | ||
super(TITLE); | ||
} | ||
|
||
public Tree getTree(){ | ||
open(); | ||
return new DefaultTree(); | ||
} | ||
|
||
/* Method to locate and select a build in the build list view */ | ||
public TreeItem getTreeItem (String... arquillianTreeItem ) { | ||
new DefaultTree(); | ||
DefaultTreeItem theTreeItem = new DefaultTreeItem (arquillianTreeItem); | ||
theTreeItem.select(); | ||
return theTreeItem; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
tests/org.jboss.tools.arquillian.ui.bot.test/resources/functions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
function searchFor(query){ | ||
$( "#search" ).val(query); | ||
var e = jQuery.Event("keyup"); | ||
e.which=13; | ||
e.keyCode=13; | ||
$ ( "#search" ).trigger(e); | ||
} | ||
|
||
function getHTML(){ | ||
return document.documentElement.innerHTML; | ||
} | ||
|
||
function getExamples(){ | ||
if ($( "#results" ).hasClass("hidden")){ | ||
return null; | ||
} | ||
var resultsDiv = getCurrentResultsDiv(); | ||
if (resultsDiv.hasClass("hidden")){ | ||
return false; | ||
} | ||
return getEachInnerText(resultsDiv.find("a")); | ||
} | ||
|
||
function getDescriptionForExample(exampleName){ | ||
if ($( "#results" ).hasClass("hidden")){ | ||
return null; | ||
} | ||
var resultsDivs = getCurrentResultsDiv(); | ||
var resultDiv = getResultDivForExample(resultsDivs, exampleName); | ||
return getEachInnerText(resultDiv.find(".list-group-item-text")); | ||
} | ||
|
||
function getLabelsForExample(exampleName){ | ||
if ($( "#results" ).hasClass("hidden")){ | ||
return null; | ||
} | ||
var resultsDivs = getCurrentResultsDiv(); | ||
var resultDiv = getResultDivForExample(resultsDivs, exampleName); | ||
return getEachInnerText(resultDiv.find("li")); | ||
} | ||
|
||
function nextPage(){ | ||
if ($( "#results" ).hasClass("hidden")){ | ||
return null; | ||
} | ||
return $( "nav.pull-right" ).find(".next").click(); | ||
} | ||
|
||
function hasNext(){ | ||
if ($( "#results" ).hasClass("hidden")){ | ||
return null; | ||
} | ||
return !$( "nav.pull-right" ).find(".next").hasClass("hidden"); | ||
} | ||
|
||
function hasPrevious(){ | ||
if ($( "#results" ).hasClass("hidden")){ | ||
return null; | ||
} | ||
return !$( "nav.pull-right" ).find(".prev").hasClass("hidden"); | ||
} | ||
|
||
function prevPage(){ | ||
if ($( "#results" ).hasClass("hidden")){ | ||
return null; | ||
} | ||
return $( "nav.pull-right" ).find(".prev").click(); | ||
} | ||
|
||
function getWizards(){ | ||
if ($( "#home" ).hasClass("hidden")){ | ||
return null; | ||
} | ||
return getEachInnerText($( "#wizards" ).find('a')); | ||
} | ||
|
||
function clickWizard(name){ | ||
$( "#wizards" ).find('a').filter(":contains('"+name+"')").click(); | ||
} | ||
|
||
function clickExample(name){ | ||
if ($( "#results" ).hasClass("hidden")){ | ||
return null; | ||
} | ||
var resultsDivs = getCurrentResultsDiv(); | ||
getResultDivForExample(resultsDivs, name).find("a").click(); | ||
} | ||
|
||
function clearSearch(){ | ||
$("a").filter(":contains('clear search')").click(); | ||
} | ||
|
||
//Internal functions from now on. Do not call them from Java tests. | ||
|
||
function getCurrentResultsDiv(){ | ||
return $( "#resultList" ).find('div'); | ||
} | ||
|
||
function getResultDivForExample(resultsDivs, exampleName){ | ||
return resultsDivs.filter(":contains('"+exampleName+"')"); | ||
} | ||
|
||
function getEachInnerText(topElement){ | ||
var resultString=""; | ||
var prefix = ""; | ||
topElement.each(function(index, element){ | ||
resultString += prefix+element.textContent; | ||
prefix=";"; | ||
}); | ||
return resultString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
...est/src/org/jboss/tools/arquillian/ui/bot/test/cruiserView/BasicArquilliaCruiserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package org.jboss.tools.arquillian.ui.bot.test.cruiserView; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.List; | ||
|
||
import org.jboss.reddeer.common.logging.Logger; | ||
import org.jboss.reddeer.common.wait.WaitUntil; | ||
import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; | ||
import org.jboss.reddeer.swt.api.TreeItem; | ||
import org.jboss.reddeer.swt.impl.browser.InternalBrowser; | ||
import org.jboss.reddeer.swt.impl.toolbar.DefaultToolItem; | ||
import org.jboss.reddeer.workbench.impl.editor.DefaultEditor; | ||
import org.jboss.reddeer.workbench.impl.editor.TextEditor; | ||
import org.jboss.reddeer.workbench.impl.shell.WorkbenchShell; | ||
import org.jboss.tools.arquillian.ui.bot.reddeer.view.ArquilliaCruiserView; | ||
import org.jboss.tools.central.reddeer.api.JavaScriptHelper; | ||
import org.jboss.tools.central.reddeer.wait.CentralIsLoaded; | ||
import org.jboss.tools.central.reddeer.wizards.NewProjectExamplesWizardDialogCentral; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Arquillia Cruiser View tests | ||
* | ||
* @author Len DiMaggio | ||
* | ||
*/ | ||
|
||
public class BasicArquilliaCruiserTest { | ||
|
||
private static Logger log = new Logger(BasicArquilliaCruiserTest.class); | ||
private static InternalBrowser centralBrowser; | ||
private static JavaScriptHelper jsHelper = JavaScriptHelper.getInstance(); | ||
|
||
private static final String STRING_1 = ".addAsResource(\"META-INF/test-persistence.xml\", \"META-INF/persistence.xml\")" ; | ||
private static final String STRING_2 = "// Kilroy was here"; | ||
private static final String QUICKSTART_SEARCH_STRING = "the `kitchensink` quickstart"; | ||
private static final String PROJECT_NAME = "jboss-kitchensink"; | ||
|
||
/* Copied from: org.jboss.tools.central.test.ui.reddeer.HTML5Test */ | ||
@Before | ||
public void setup() { | ||
new DefaultToolItem(new WorkbenchShell(), "JBoss Central").click(); | ||
// activate central editor | ||
new DefaultEditor("JBoss Central"); | ||
new WaitUntil(new CentralIsLoaded()); | ||
centralBrowser = new InternalBrowser(); | ||
jsHelper.setBrowser(centralBrowser); | ||
} | ||
|
||
/** | ||
* Test to verify dynamic updating of asset tree in Arquillia View | ||
* | ||
* Test steps: | ||
* Import the quickstart | ||
* Select the project in the project explorer view | ||
* Open the Arquillia Cruiser view | ||
* Select the project in the Arquillia Cruiser view | ||
* Find persistence.xml in the Arquillia Cruiser view | ||
* Open MemberRegistration.java | ||
* Delete this line: .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml") | ||
* Save file, verify persistence.xml is removed from Arquillia Cruiser view | ||
* Restore edit, verify persistence.xml is back in Arquillia Cruiser view | ||
* | ||
* @throws InterruptedException | ||
*/ | ||
|
||
@Test | ||
public void dynamicUpdateTest () { | ||
|
||
/* Import the quickstart */ | ||
jsHelper.searchFor(QUICKSTART_SEARCH_STRING); | ||
String[] examples = jsHelper.getExamples(); | ||
assertTrue("One example should be found", examples.length == 1); | ||
importExample(examples[0]); | ||
jsHelper.clearSearch(); | ||
|
||
/* Select the project in the project explorer */ | ||
log.step("Select the project in the project explorer"); | ||
ProjectExplorer projectExplorer = new ProjectExplorer(); | ||
projectExplorer.open(); | ||
projectExplorer.getProject(PROJECT_NAME).select(); | ||
|
||
/* Locate the project in the Arquillia Cruiser View */ | ||
log.step("Locate the project in the Arquillia Cruiser View"); | ||
ArquilliaCruiserView arquilliaCruiserView = new ArquilliaCruiserView(); | ||
arquilliaCruiserView.open(); | ||
|
||
/* Verify that the persistence.xml file is present */ | ||
log.step("Verify that the persistence.xml file is present"); | ||
assertTrue ("presistence.xml file should be located in Arquillia View", findStringInTreeItemList (arquilliaCruiserView.getTree().getAllItems(), "persistence.xml")); | ||
|
||
/* Remove the reference to persistence.xml from the MemberRegistrationTest.java file */ | ||
log.step("Remove the reference to persistence.xml from the MemberRegistrationTest.java file"); | ||
arquilliaCruiserView.getTreeItem("jboss-kitchensink", "src/test/java", "org.jboss.as.quickstarts.kitchensink.test", "MemberRegistrationTest.java").doubleClick(); | ||
editFile (STRING_1, STRING_2); | ||
|
||
/* And confirm that persistance.xml file is dynamically removed from the Arquillia Cruiser View */ | ||
log.step("Confirm that persistance.xml file is dynamically removed from the Arquillia Cruiser View"); | ||
projectExplorer.getProject("jboss-kitchensink").select(); | ||
assertFalse ("presistence.xml file should not be located in Arquillia View", findStringInTreeItemList (arquilliaCruiserView.getTree().getAllItems(), "persistence.xml")); | ||
|
||
/* Restore the reference to persistence.xml from the MemberRegistrationTest.java file */ | ||
log.step("Restore the reference to persistence.xml from the MemberRegistrationTest.java file"); | ||
arquilliaCruiserView.getTreeItem("jboss-kitchensink", "src/test/java", "org.jboss.as.quickstarts.kitchensink.test", "MemberRegistrationTest.java").doubleClick(); | ||
editFile (STRING_2, STRING_1); | ||
|
||
/* And confirm that persistance.xml file is dynamically restored to the Arquillia Cruiser View */ | ||
log.step("Confirm that persistance.xml file is dynamically restored to the Arquillia Cruiser View"); | ||
projectExplorer.getProject("jboss-kitchensink").select(); | ||
assertTrue ("presistence.xml file should be located in Arquillia View", findStringInTreeItemList (arquilliaCruiserView.getTree().getAllItems(), "persistence.xml")); | ||
} | ||
|
||
/** | ||
* Search for List of TreeItem objects by name/text | ||
* | ||
* @param treeItems | ||
* @param searchString | ||
* @return True or false | ||
*/ | ||
private boolean findStringInTreeItemList (List<TreeItem> treeItems, String searchString) { | ||
boolean retValue = false; | ||
for(TreeItem currentItem : treeItems) { | ||
if (currentItem.getText().equals(searchString)) { | ||
retValue = true; | ||
break; | ||
} | ||
} | ||
return retValue; | ||
} | ||
|
||
/** | ||
* Replace a string in a TextEditor | ||
* | ||
* @param originalText | ||
* @param editedText | ||
*/ | ||
private void editFile (String originalText, String editedText) { | ||
TextEditor theEditor = new TextEditor(); | ||
theEditor.setText(theEditor.getText().replace(originalText, editedText)); | ||
theEditor.save(); | ||
} | ||
|
||
/** | ||
* Import an example in JBoss Central | ||
* Copied from: org.jboss.tools.central.test.ui.reddeer.HTML5Test | ||
* | ||
* @param exampleName | ||
*/ | ||
private void importExample(String exampleName) { | ||
log.step("Importing example: " + exampleName); | ||
jsHelper.clickExample(exampleName); | ||
NewProjectExamplesWizardDialogCentral wizardDialog = new NewProjectExamplesWizardDialogCentral(); | ||
wizardDialog.finish(exampleName); | ||
} | ||
|
||
} |