You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2009/12/04 10:27:31 UTC
svn commit: r887126 - in /ofbiz/trunk/framework/testtools:
src/org/ofbiz/testtools/seleniumxml/ testdef/seleniumxml/example/
Author: jleroux
Date: Fri Dec 4 09:27:30 2009
New Revision: 887126
URL: http://svn.apache.org/viewvc?rev=887126&view=rev
Log:
A patch from Erwan de FERRIERES "seleniumXML improvement and corrections" (https://issues.apache.org/jira/browse/OFBIZ-3296) - OFBIZ-3296
corrected the XML tests
added new functions in selenium for better conversion from selenese and use with the XML tests :
* echo
* verifyTextPresent
* verifyTextNotPresent
* assertTitle
* assertConfirmation
Removed comments
* waitForPageToLoad : just wait the page to load before any other action (time in ms)
* click : make a click on an element
* assertContains : assert an element contains some code.
Modified:
ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumIDEConverter.java
ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java
ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_new.xml
ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_search.xml
Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumIDEConverter.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumIDEConverter.java?rev=887126&r1=887125&r2=887126&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumIDEConverter.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumIDEConverter.java Fri Dec 4 09:27:30 2009
@@ -44,7 +44,7 @@
private Element xmlDestRoot;
private Namespace ns = Namespace.getNamespace("http://www.w3.org/1999/xhtml");
private Map root;
-
+
public void convert(String ideFile, String xmlFile) throws JDOMException, IOException, SAXException, ParserConfigurationException {
readInputFile(ideFile);
convertIDECommands();
@@ -54,7 +54,7 @@
private void readInputFile(String input) throws JDOMException, IOException, SAXException, ParserConfigurationException {
File xmlFile = new File(input);
SAXBuilder builder = new SAXBuilder();
- this.ideFile = builder.build(xmlFile);
+ this.ideFile = builder.build(xmlFile);
}
private void createSeleniumXml(String outputFile) {
@@ -93,29 +93,42 @@
System.out.println("Found clickAndWait");
this.xmlDestRoot.addContent(buildCommand("click", "locator", cmd.get(1).getValue(), null, null));
this.xmlDestRoot.addContent(buildCommand("waitForPageToLoad", "value", "10000", null, null));
-
} else if ("type".compareTo(cmdElem.getValue()) == 0 ) {
System.out.println("Found type");
this.xmlDestRoot.addContent (buildCommand("type", "name", cmd.get(1).getValue(), "value", cmd.get(2).getValue()));
-
} else if ("select".compareTo(cmdElem.getValue()) == 0) {
System.out.println("Found select");
this.xmlDestRoot.addContent(buildCommand("select", "locator", cmd.get(1).getValue(), "option", cmd.get(2).getValue()));
-
} else if ("open".compareTo(cmdElem.getValue()) == 0) {
System.out.println("Found open");
this.xmlDestRoot.addContent(buildCommand("open", "value", cmd.get(1).getValue(), null, null));
-
} else if ("click".compareTo(cmdElem.getValue()) == 0) {
Element newCmd = new Element("click");
newCmd.setAttribute("locator", cmd.get(1).getValue());
this.xmlDestRoot.addContent(newCmd);
-
} else if ("doubleClick".compareTo(cmdElem.getValue()) == 0) {
Element newCmd = new Element("doubleClick");
newCmd.setAttribute("locator", cmd.get(1).getValue());
this.xmlDestRoot.addContent(newCmd);
-
+ } else if ("echo".compareTo(cmdElem.getValue()) == 0) {
+ System.out.println("Found echo");
+ Element newCmd = new Element("print");
+ newCmd.setAttribute("value", cmd.get(1).getValue());
+ this.xmlDestRoot.addContent(newCmd);
+ } else if ("verifyTextPresent".compareTo(cmdElem.getValue()) == 0) {
+ System.out.println("Found verifyTextPresent");
+ this.xmlDestRoot.addContent(buildCommand("getBodyText", "out", "bodySource", null, null));
+ this.xmlDestRoot.addContent(buildCommand("assertContains", "test", cmd.get(1).getValue(), "src", "${bodySource}"));
+ } else if ("verifyTextNotPresent".compareTo(cmdElem.getValue()) == 0) {
+ System.out.println("Found verifyTextNotPresent");
+ this.xmlDestRoot.addContent(buildCommand("getBodyText", "out", "bodySource", null, null));
+ this.xmlDestRoot.addContent(buildCommand("assertNotContains", "test", cmd.get(1).getValue(), "src", "${bodySource}"));
+ } else if ("assertTitle".compareTo(cmdElem.getValue()) == 0) {
+ System.out.println("Found assertTitle");
+ this.xmlDestRoot.addContent(buildCommand("assertTitle", "value", cmd.get(1).getValue(), null, null));
+ } else if ("assertConfirmation".compareTo(cmdElem.getValue()) == 0) {
+ System.out.println("Found assertConfirmation");
+ this.xmlDestRoot.addContent(buildCommand("assertConfirmation", "value", cmd.get(1).getValue(), null, null));
} else {
System.out.println("WARNING: No definition for " + cmdElem.getValue() + " defaulting to us 'reflection'.");
Element newCmd = new Element(cmdElem.getValue());
Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java?rev=887126&r1=887125&r2=887126&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java Fri Dec 4 09:27:30 2009
@@ -270,6 +270,8 @@
testcase(elem);
} else if("assertContains" == thisName) {
assertContains(elem);
+ } else if("assertNotContains" == thisName) {
+ assertNotContains(elem);
} else if("getHtmlSource" == thisName) {
getHtmlSource(elem);
} else if("getBodyText" == thisName) {
@@ -288,11 +290,11 @@
appendCmd(elem);
} else if("loadParameter" == thisName) {
loadParameter(elem);
- }else if("partialRunDependency" == thisName) {
+ } else if("partialRunDependency" == thisName) {
partialRunDependency(elem);
- }else if("if" == thisName) {
+ } else if("if" == thisName) {
ifCmd(elem);
- }else if("open" == thisName) {
+ } else if("open" == thisName) {
openCmd(elem);
} else if("click" == thisName) {
clickCmd(elem);
@@ -316,9 +318,11 @@
openWindow(elem);
} else if("selectWindow" == thisName) {
selectWindow(elem);
+ } else if("assertConfirmation" == thisName) {
+ assertConfirmation(elem);
} else if("runScript" == thisName) {
runScript(elem);
- } else {
+ } else {
logger.info("Undefined command calling by reflection for command: " + thisName);
callByReflection(elem);
}
@@ -362,7 +366,6 @@
}
public void waitForValue(Element elem) {
-
String locator = replaceParam(elem.getAttributeValue("locator"));
String timeout = elem.getAttributeValue("timeout");
String outParam = elem.getAttributeValue("out");
@@ -541,13 +544,36 @@
if(indxSearch == -1) {
logger.info("assertContains didn't find " + test + " in the src");
throw new TestCaseException("assertContains didn't find: " + test);
-
} else {
logger.info("assertContains found " + test + " in the src");
}
//TODO: implement JUnit TestCase - Assert.assertTrue(indxSearch != -1);
}
+ private void assertNotContains(Element elem) throws TestCaseException {
+ String src = replaceParam(elem.getAttributeValue("src"));
+ String test = replaceParam(elem.getAttributeValue("test"));
+ int indxSearch = src.indexOf(test);
+ if(indxSearch != -1) {
+ logger.info("assertNotContains found " + test + " in the src");
+ throw new TestCaseException("assertContains didn't find: " + test);
+ } else {
+ logger.info("assertNotContains didn't find " + test + " in the src");
+ }
+ }
+
+ private void assertTitle(Element elem) throws TestCaseException {
+ String src = replaceParam(this.sel.getTitle());
+ String test = replaceParam(elem.getAttributeValue("value"));
+ int indxSearch = src.indexOf(test);
+ if(indxSearch == -1) {
+ logger.info("assertTitle value " + test + " doesn't match exact "+src);
+ throw new TestCaseException("assertTitle value " + test + " doesn't match exact "+src);
+ } else {
+ logger.info("assertTitle matched title");
+ }
+ }
+
private void selectPopup(Element elem) {
String locator = elem.getAttributeValue("locator");
String timeout = elem.getAttributeValue("timeout");
@@ -591,12 +617,14 @@
logger.info("getSelectedValue: locator=" + locator + " text="+text);
addParam(out, text);
}
+
private void getSelectedId(Element elem) {
String locator = elem.getAttributeValue("locator");
String out = elem.getAttributeValue("out");
String text = this.sel.getSelectedId(locator);
addParam(out, text);
}
+
private void getHtmlSource(Element elem) {
String paramName = elem.getAttributeValue("out");
String text = this.sel.getHtmlSource();
@@ -609,6 +637,7 @@
String text = this.sel.getBodyText();
addParam(paramName, text);
}
+
private void testcase(Element elem) {
System.err.println("New testcase: " + elem.getAttributeValue("file"));
String testFile = elem.getAttributeValue("file");
@@ -642,6 +671,7 @@
}
return directory;
}
+
private void clickAt(Element elem) {
logger.debug("clickAt: " + replaceParam(elem.getAttributeValue("locator")));
String locator = replaceParam(elem.getAttributeValue("locator"));
@@ -649,6 +679,12 @@
this.sel.clickAt(locator, coordString);
}
+ private void assertConfirmation(Element elem) {
+ logger.debug("assertConfirmation: " + replaceParam(elem.getAttributeValue("value")));
+ this.sel.waitForCondition("selenium.isConfirmationPresent();", "1000");
+ this.sel.getConfirmation();
+ }
+
/**
* @param elem takes a Selenium String locator. See Javadocs for more information. Here are some
* example locators:
@@ -662,9 +698,7 @@
try {
this.sel.click(replaceParam(elem.getAttributeValue("locator")));
} catch (SeleniumException e) {
-
logger.info("caught SeleniumException Name:"+elem.getName()+" , Value: "+elem.getAttributeValue("locator"));
-
e.printStackTrace();
}
}
Modified: ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_new.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_new.xml?rev=887126&r1=887125&r2=887126&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_new.xml (original)
+++ ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_new.xml Fri Dec 4 09:27:30 2009
@@ -20,11 +20,9 @@
<waitForPageToLoad value="10000" />
<click locator="link=Items" />
<waitForPageToLoad value="10000" />
- <type name="description" value="Item 1" />
+ <type name="AddExampleItem_description" value="Item 1" />
<type name="amount" value="100" />
<select locator="amountUomId" option="label=Weight: Stone (st)" />
<click locator="submitButton" />
- <waitForPageToLoad value="10000" />
- <!-- click locator="link=New Example" />
- <waitForPageToLoad value="10000" / -->
+ <assertConfirmation value="Do you confirm ?" />
</testcase>
\ No newline at end of file
Modified: ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_search.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_search.xml?rev=887126&r1=887125&r2=887126&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_search.xml (original)
+++ ofbiz/trunk/framework/testtools/testdef/seleniumxml/example/example_search.xml Fri Dec 4 09:27:30 2009
@@ -1,11 +1,8 @@
<testcase>
- <click locator="link=Example" />
+ <open value="/example/control/FindExample" />
<waitForPageToLoad value="10000" />
<click locator="searchButton" />
<waitForPageToLoad value="10000" />
- <!-- click locator="link=Last" />
- <waitForPageToLoad value="10000" / -->
<getHtmlSource out="searchResults"/>
- <!-- assertContains src="${searchResults}" test="${exampleName}" / -->
<assertContains src="${searchResults}" test="Brett" />
</testcase>
\ No newline at end of file