jwebunit-development Mailing List for JWebUnit (Page 7)
Brought to you by:
henryju
You can subscribe to this list here.
| 2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(98) |
Jul
(45) |
Aug
(49) |
Sep
(90) |
Oct
(28) |
Nov
(18) |
Dec
(17) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2005 |
Jan
(14) |
Feb
(21) |
Mar
(52) |
Apr
(39) |
May
(61) |
Jun
(35) |
Jul
(42) |
Aug
(31) |
Sep
(34) |
Oct
(16) |
Nov
(14) |
Dec
(61) |
| 2006 |
Jan
(39) |
Feb
(11) |
Mar
(29) |
Apr
(29) |
May
(30) |
Jun
(145) |
Jul
(61) |
Aug
(40) |
Sep
(36) |
Oct
(66) |
Nov
(50) |
Dec
(11) |
| 2007 |
Jan
(30) |
Feb
(1) |
Mar
(47) |
Apr
(9) |
May
(36) |
Jun
(13) |
Jul
(7) |
Aug
(5) |
Sep
(6) |
Oct
(3) |
Nov
(11) |
Dec
(36) |
| 2008 |
Jan
(12) |
Feb
|
Mar
(4) |
Apr
(29) |
May
(1) |
Jun
(8) |
Jul
(10) |
Aug
|
Sep
(2) |
Oct
(77) |
Nov
(107) |
Dec
(46) |
| 2009 |
Jan
(17) |
Feb
(13) |
Mar
(27) |
Apr
(5) |
May
(8) |
Jun
(17) |
Jul
(10) |
Aug
(25) |
Sep
(15) |
Oct
(4) |
Nov
(4) |
Dec
(10) |
| 2010 |
Jan
|
Feb
(6) |
Mar
(12) |
Apr
(15) |
May
(4) |
Jun
(5) |
Jul
(9) |
Aug
(5) |
Sep
(5) |
Oct
(63) |
Nov
(9) |
Dec
(1) |
| 2011 |
Jan
(9) |
Feb
(3) |
Mar
(15) |
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
(14) |
Sep
(15) |
Oct
(11) |
Nov
(1) |
Dec
(2) |
| 2012 |
Jan
(6) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(14) |
Aug
(17) |
Sep
(8) |
Oct
(1) |
Nov
(17) |
Dec
|
| 2014 |
Jan
|
Feb
|
Mar
(13) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
|
Dec
|
| 2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
(13) |
Aug
|
Sep
|
Oct
(4) |
Nov
|
Dec
|
|
From: Julien H. <he...@ya...> - 2011-03-25 08:30:19
|
Hi Jevon,
I just tried and I can't reproduce the issue. Note that I am using Maven 3.0.3
on Windows so maybe the issue you are facing is related to Maven version or OS.
Can you send me the full build log trace (mvn test -X > build.log) and also the
dependency tree (mvn dependency:tree > tree.log).
Thanks
Julien
----- Message d'origine ----
> De : Jevon Wright <je...@je...>
> À : JWebUnit Development mail list
<jwe...@li...>
> Envoyé le : Ven 25 mars 2011, 6h 58min 40s
> Objet : [JWebUnit-development] mvn test crashes with NoSuchMethodError on
>Mockito.when
>
> Hi,
>
> I am trying to get JWebUnit trunk to test using mvn ("mvn test"), but
> the tests crash quickly with an error:
>
> Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.969
> sec <<< FAILURE!
>testAssertImageSrcContainsShouldDelegateXPathExpressionToUnderlyingTestingEngine(net.sourceforge.jwebunit.junit.WebTesterTest)
>)
> Time elapsed: 0.468 sec <<< ERROR!
> java.lang.NoSuchMethodError:
>org.mockito.Mockito.when(Ljava/lang/Object;)Lorg/mockito/internal/progress/NewOngoingStubbing;
>;
> at
>net.sourceforge.jwebunit.junit.WebTesterTest.engine(WebTesterTest.java:57)
> at
>net.sourceforge.jwebunit.junit.WebTesterTest.testAssertImageSrcContainsShouldDelegateXPathExpressionToUnderlyingTestingEngine(WebTesterTest.java:32)
>
> ...
>
> According to [1] this is due to multiple versions of Mockito being on
> the class path. Is this a Maven configuration setting? Any ideas on
> how to fix the problem? I'm still a Maven novice so any help would be
> appreciated. :)
>
> Jevon
>
> [1]:
>http://groups.google.com/group/mockito/browse_thread/thread/6c21dc83d1974ead?pli=1
>
>
> ------------------------------------------------------------------------------
> Enable your software for Intel(R) Active Management Technology to meet the
> growing manageability and security demands of your customers. Businesses
> are taking advantage of Intel(R) vPro (TM) technology - will your software
> be a part of the solution? Download the Intel(R) Manageability Checker
> today! http://p.sf.net/sfu/intel-dev2devmar
> _______________________________________________
> JWebUnit-development mailing list
> JWe...@li...
> https://lists.sourceforge.net/lists/listinfo/jwebunit-development
>
|
|
From: Jevon W. <je...@je...> - 2011-03-25 05:58:47
|
Hi,
I am trying to get JWebUnit trunk to test using mvn ("mvn test"), but
the tests crash quickly with an error:
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.969
sec <<< FAILURE!
testAssertImageSrcContainsShouldDelegateXPathExpressionToUnderlyingTestingEngine(net.sourceforge.jwebunit.junit.WebTesterTest)
Time elapsed: 0.468 sec <<< ERROR!
java.lang.NoSuchMethodError:
org.mockito.Mockito.when(Ljava/lang/Object;)Lorg/mockito/internal/progress/NewOngoingStubbing;
at net.sourceforge.jwebunit.junit.WebTesterTest.engine(WebTesterTest.java:57)
at net.sourceforge.jwebunit.junit.WebTesterTest.testAssertImageSrcContainsShouldDelegateXPathExpressionToUnderlyingTestingEngine(WebTesterTest.java:32)
...
According to [1] this is due to multiple versions of Mockito being on
the class path. Is this a Maven configuration setting? Any ideas on
how to fix the problem? I'm still a Maven novice so any help would be
appreciated. :)
Jevon
[1]: http://groups.google.com/group/mockito/browse_thread/thread/6c21dc83d1974ead?pli=1
|
|
From: <he...@us...> - 2011-03-21 16:20:24
|
Revision: 901
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=901&view=rev
Author: henryju
Date: 2011-03-21 16:20:16 +0000 (Mon, 21 Mar 2011)
Log Message:
-----------
Improved support of webdriver.
Modified Paths:
--------------
branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
branches/webdriver/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/InvalidActionForm.html
branches/webdriver/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebDriverTestingEngineImpl.java
branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/webdriver/JWebUnitTest.java
Added Paths:
-----------
branches/webdriver/jwebunit-webdriver-plugin/pom.xml
branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebdriverElementImpl.java
Modified: branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java
===================================================================
--- branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java 2011-03-18 22:07:48 UTC (rev 900)
+++ branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FormSubmissionTest.java 2011-03-21 16:20:16 UTC (rev 901)
@@ -64,7 +64,7 @@
setTextField("text", "sometext");
submit("button");
assertTextPresent("Submitted parameters");
- assertTextPresent("Params are:" + System.getProperty("line.separator") + "text=sometext");
+ assertTextPresent("Params are:\ntext=sometext");
clickLink("return");
setTextField("text", "anothertext");
submit();
@@ -134,7 +134,7 @@
checkCheckbox("checkBox", "3");
checkCheckbox("checkBox", "3"); // check for duplicates
submit();
- assertTextPresent("checkBox=1,3" + System.getProperty("line.separator"));
+ assertTextPresent("checkBox=1,3\n");
}
@Test
@@ -156,7 +156,7 @@
setTextField("color", "blue");
uncheckCheckbox("checkBox");
submit();
- assertTextPresent("color=blue" + System.getProperty("line.separator"));
+ assertTextPresent("color=blue\n");
}
@Test
@@ -165,7 +165,7 @@
clickRadioOption("radio", "1");
assertRadioOptionSelected("radio", "1");
submit();
- assertTextPresent("radio=1" + System.getProperty("line.separator"));
+ assertTextPresent("radio=1\n");
clickLink("return");
clickRadioOption("radio", "2");
clickRadioOption("radio", "3");
@@ -173,7 +173,7 @@
assertRadioOptionNotSelected("radio", "2");
assertRadioOptionSelected("radio", "3");
submit();
- assertTextPresent("radio=3" + System.getProperty("line.separator"));
+ assertTextPresent("radio=3\n");
}
@Test
@@ -181,7 +181,7 @@
beginAt("/SingleUnnamedButtonForm.html");
setTextField("color", "blue");
submit();
- assertTextPresent("color=blue" + System.getProperty("line.separator"));
+ assertTextPresent("color=blue\n");
}
@Test
@@ -196,7 +196,7 @@
public void testSingleFormMultipleButtonSubmission() {
gotoMultiButtonPage();
submit("color");
- assertTextPresent("Params are:" + System.getProperty("line.separator") + "color=red");
+ assertTextPresent("Params are:\ncolor=red");
gotoMultiButtonPage();
submit("color", "blue");
assertTextPresent("color=blue");
@@ -284,7 +284,7 @@
beginAt("/MultiFormPage.html");
setTextField("param2", "anyvalue");
submit("button2b");
- assertTextPresent("param2=anyvalue" + System.getProperty("line.separator"));
+ assertTextPresent("param2=anyvalue\n");
assertTextPresent("button2b=b2b");
}
Modified: branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java
===================================================================
--- branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java 2011-03-18 22:07:48 UTC (rev 900)
+++ branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/FramesAndWindowsTest.java 2011-03-21 16:20:16 UTC (rev 901)
@@ -55,7 +55,7 @@
@Test public void testGotoWindow() {
gotoRootAndOpenChild("ChildPage1");
gotoWindow("ChildPage1");
- assertTextPresent("child 1");
+ assertTextPresent("Child Page 1");
}
@Test public void testGotoWindowByID() {
@@ -87,7 +87,7 @@
assertTitleEquals("This is the Root");
clickLink("ChildPage1");
gotoWindow("ChildPage1");
- assertTextPresent("child 1");
+ assertTextPresent("Child Page 1");
closeWindow();
assertWindowCountEquals(1);
assertTitleEquals("This is the Root");
@@ -161,7 +161,7 @@
assertFormPresent();
setTextField("color", "red");
submit("submit");
- assertTextPresent("color=red" + System.getProperty("line.separator"));
+ assertTextPresent("color=red\n");
}
@Test public void testFormInputInInlineFrame() {
@@ -170,7 +170,7 @@
assertFormPresent();
setTextField("color", "red");
submit("submit");
- assertTextPresent("color=red" + System.getProperty("line.separator"));
+ assertTextPresent("color=red\n");
}
//TODO this just posts to a new frameset inside the frame, is the test needed?
Modified: branches/webdriver/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/InvalidActionForm.html
===================================================================
--- branches/webdriver/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/InvalidActionForm.html 2011-03-18 22:07:48 UTC (rev 900)
+++ branches/webdriver/jwebunit-commons-tests/src/main/resources/testcases/FormSubmissionTest/InvalidActionForm.html 2011-03-21 16:20:16 UTC (rev 901)
@@ -23,9 +23,9 @@
<head></head>
<body>
<form method=GET action="nonExistingPage">
- <input name="button1" value="b1" type=submit>
- <input name="color" value="red" type=submit>
- <input name="color" value="blue" type=submit>
+ <input name="button1" value="b1" type="submit">
+ <input name="color" value="red" type="submit">
+ <input name="color" value="blue" type="submit">
</form>
</body>
</html>
\ No newline at end of file
Modified: branches/webdriver/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
===================================================================
--- branches/webdriver/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-03-18 22:07:48 UTC (rev 900)
+++ branches/webdriver/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-03-21 16:20:16 UTC (rev 901)
@@ -713,7 +713,7 @@
public String getPageText() {
Page page = win.getEnclosedPage();
if (page instanceof HtmlPage) {
- return ((HtmlPage) page).asText();
+ return ((HtmlPage) page).getBody().asText();
}
if (page instanceof TextPage) {
return ((TextPage) page).getContent();
@@ -1365,7 +1365,7 @@
* @return <code>true</code> when the button with text could be found.
*/
public boolean hasButtonWithText(String text) {
- return getButtonWithText(text) != null ? true : false;
+ return getButtonWithText(text) != null;
}
/**
Added: branches/webdriver/jwebunit-webdriver-plugin/pom.xml
===================================================================
--- branches/webdriver/jwebunit-webdriver-plugin/pom.xml (rev 0)
+++ branches/webdriver/jwebunit-webdriver-plugin/pom.xml 2011-03-21 16:20:16 UTC (rev 901)
@@ -0,0 +1,67 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>jwebunit</artifactId>
+ <groupId>net.sourceforge.jwebunit</groupId>
+ <version>3.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jwebunit-webdriver-plugin</artifactId>
+ <name>Webdriver Plugin</name>
+ <description>Webdriver plugin for JWebUnit.</description>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <testFailureIgnore>true</testFailureIgnore>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit-dep</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-htmlunit-driver</artifactId>
+ <version>2.0b2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-support</artifactId>
+ <version>2.0b2</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.jwebunit</groupId>
+ <artifactId>jwebunit-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.jwebunit</groupId>
+ <artifactId>jwebunit-commons-tests</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ </dependencies>
+ <properties>
+ <topDirectoryLocation>..</topDirectoryLocation>
+ </properties>
+</project>
Modified: branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebDriverTestingEngineImpl.java
===================================================================
--- branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebDriverTestingEngineImpl.java 2011-03-18 22:07:48 UTC (rev 900)
+++ branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebDriverTestingEngineImpl.java 2011-03-21 16:20:16 UTC (rev 901)
@@ -18,18 +18,23 @@
*/
package net.sourceforge.jwebunit.webdriver;
+import org.apache.regexp.RE;
+import org.apache.regexp.RESyntaxException;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+
import com.gargoylesoftware.htmlunit.BrowserVersion;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.logging.Level;
-
+import net.sourceforge.jwebunit.api.HttpHeader;
import net.sourceforge.jwebunit.api.IElement;
import net.sourceforge.jwebunit.api.ITestingEngine;
import net.sourceforge.jwebunit.exception.ExpectedJavascriptAlertException;
@@ -43,12 +48,13 @@
import net.sourceforge.jwebunit.util.TestContext;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
+import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
-
+import org.openqa.selenium.support.ui.Select;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -76,6 +82,10 @@
public void beginAt(URL aInitialURL, TestContext aTestContext) throws TestingEngineResponseException {
this.setTestContext(aTestContext);
driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3);
+ ((HtmlUnitDriver) driver).setJavascriptEnabled(true);
+
+ //Reset form
+ formIdent = null;
gotoPage(aInitialURL);
}
@@ -85,10 +95,12 @@
}
public void closeBrowser() throws ExpectedJavascriptAlertException, ExpectedJavascriptConfirmException, ExpectedJavascriptPromptException {
+ formIdent = null;
driver.close();
}
public void gotoPage(URL url) throws TestingEngineResponseException {
+ formIdent = null;
driver.get(url.toString());
}
@@ -167,11 +179,11 @@
}
public void gotoWindow(int windowID) {
- driver.switchTo().window("" + windowID);
+ throw new UnsupportedOperationException("Not supported yet.");
}
public void gotoRootWindow() {
- driver.switchTo().window("top");
+ throw new UnsupportedOperationException("Not supported yet.");
}
public int getWindowCount() {
@@ -179,6 +191,7 @@
}
public void closeWindow() {
+ formIdent = null;
driver.close();
}
@@ -262,139 +275,222 @@
}
public String getTextFieldValue(String paramName) {
- WebElement e = getWebElementByXPath("/input[@type='text' and @name='" + paramName + "']", false);
+ WebElement e = getWebElementByXPath("//input[@type='text' and @name='" + paramName + "']", false);
return e.getValue();
}
public String getHiddenFieldValue(String paramName) {
- throw new UnsupportedOperationException("Not supported yet.");
+ WebElement e = getWebElementByXPath("//input[@type='hidden' and @name='" + paramName + "']", false);
+ return e.getValue();
}
public void setTextField(String inputName, String text) {
- WebElement e = getWebElementByXPath("/input[@type='text' and @name='" + inputName + "']", false);
+ WebElement e = getWebElementByXPath("//input[@type='text' and @name='" + inputName + "']", false);
if (e == null) {
- e = getWebElementByXPath("/textarea[@name='" + inputName + "']", false);
+ e = getWebElementByXPath("//textarea[@name='" + inputName + "']", false);
}
if (e == null) {
- e = getWebElementByXPath("/input[@type='file' and @name='" + inputName + "']", false);
+ e = getWebElementByXPath("//input[@type='file' and @name='" + inputName + "']", false);
}
e.clear();
e.sendKeys(text);
}
public void setHiddenField(String inputName, String text) {
- throw new UnsupportedOperationException("Not supported yet.");
+ WebElement e = getWebElementByXPath("//input[@type='hidden' and @name='" + inputName + "']", false);
+ ((JavascriptExecutor)driver).executeScript("arguments[0].value=" + escapeQuotes(text), e);
}
public String[] getSelectOptionValues(String selectName) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return getSelectOptionValues(selectName, 0);
}
public String[] getSelectOptionValues(String selectName, int index) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "' and position()=" + (index + 1) + "]", true));
+ ArrayList<String> result = new ArrayList<String>();
+ for (WebElement opt : select.getOptions()) {
+ result.add(opt.getValue());
+ }
+ return result.toArray(new String[result.size()]);
}
public String[] getSelectedOptions(String selectName) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return getSelectedOptions(selectName, 0);
}
+ private String[] getSelectedOptions(Select select) {
+ String[] result = new String[select.getAllSelectedOptions().size()];
+ int i = 0;
+ for (WebElement opt : select.getAllSelectedOptions()) {
+ result[i++] = opt.getValue();
+ }
+ return result;
+ }
+
public String[] getSelectedOptions(String selectName, int index) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "' and position()=" + (index + 1) + "]", true));
+ return getSelectedOptions(select);
}
+ private String getSelectOptionValueForLabel(Select select, String label) {
+ for (WebElement opt : select.getOptions()) {
+ if (opt.getText().equals(label)) {
+ return opt.getValue();
+ }
+ }
+ throw new RuntimeException("Unable to find option " + label);
+ }
+
+ private String getSelectOptionLabelForValue(Select select, String value) {
+ for (WebElement opt : select.getOptions()) {
+ if (opt.getValue().equals(value)) {
+ return opt.getText();
+ }
+ }
+ throw new RuntimeException("Unable to find option " + value);
+ }
+
public String getSelectOptionLabelForValue(String selectName, String optionValue) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "']", true));
+ return getSelectOptionLabelForValue(select, optionValue);
}
public String getSelectOptionLabelForValue(String selectName, int index, String optionValue) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "' and position()=" + (index + 1) + "]", true));
+ return getSelectOptionLabelForValue(select, optionValue);
}
public String getSelectOptionValueForLabel(String selectName, String optionLabel) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "']", true));
+ return getSelectOptionValueForLabel(select, optionLabel);
}
public String getSelectOptionValueForLabel(String selectName, int index, String optionLabel) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "' and position()=" + (index + 1) + "]", true));
+ return getSelectOptionValueForLabel(select, optionLabel);
}
public void selectOptions(String selectName, String[] optionValues) {
- throw new UnsupportedOperationException("Not supported yet.");
+ selectOptions(selectName, 0, optionValues);
}
public void selectOptions(String selectName, int index, String[] optionValues) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "' and position()=" + (index + 1) + "]", true));
+ if (!select.isMultiple() && optionValues.length > 1)
+ throw new RuntimeException("Multiselect not enabled");
+ for (String option : optionValues) {
+ boolean found = false;
+ for (WebElement opt : select.getOptions()) {
+ if (opt.getValue().equals(option)) {
+ select.selectByValue(option);
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ throw new RuntimeException("Option " + option
+ + " not found");
+ }
+ }
}
public void unselectOptions(String selectName, String[] optionValues) {
- throw new UnsupportedOperationException("Not supported yet.");
+ unselectOptions(selectName, 0, optionValues);
}
public void unselectOptions(String selectName, int index, String[] optionValues) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "' and position()=" + (index + 1) + "]", true));
+ if (!select.isMultiple() && optionValues.length > 1)
+ throw new RuntimeException("Multiselect not enabled");
+ for (String option : optionValues) {
+ boolean found = false;
+ for (WebElement opt : select.getOptions()) {
+ if (opt.getValue().equals(option)) {
+ select.deselectByValue(option);
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ throw new RuntimeException("Option " + option
+ + " not found");
+ }
+ }
}
public boolean hasSelectOption(String selectName, String optionLabel) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return hasSelectOption(selectName, 0, optionLabel);
}
public boolean hasSelectOptionValue(String selectName, String optionValue) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return hasSelectOptionValue(selectName, 0, optionValue);
}
public boolean hasSelectOption(String selectName, int index, String optionLabel) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "' and position()=" + (index + 1) + "]", true));
+ for (WebElement opt : select.getOptions()) {
+ if (opt.getText().equals(optionLabel)) {
+ return true;
+ }
+ }
+ return false;
}
public boolean hasSelectOptionValue(String selectName, int index, String optionValue) {
- throw new UnsupportedOperationException("Not supported yet.");
+ Select select = new Select(getWebElementByXPath("//select[@name='" + selectName + "' and position()=" + (index + 1) + "]", true));
+ for (WebElement opt : select.getOptions()) {
+ if (opt.getValue().equals(optionValue)) {
+ return true;
+ }
+ }
+ return false;
}
public boolean isCheckboxSelected(String checkBoxName) {
- WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "']", true);
+ WebElement e = getWebElementByXPath("//input[@type='checkbox' and @name='" + checkBoxName + "']", true);
return e.isSelected();
}
public boolean isCheckboxSelected(String checkBoxName, String checkBoxValue) {
- WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "' and @value='" + checkBoxValue + "']", true);
+ WebElement e = getWebElementByXPath("//input[@type='checkbox' and @name='" + checkBoxName + "' and @value='" + checkBoxValue + "']", true);
return e.isSelected();
}
public void checkCheckbox(String checkBoxName) {
- WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "']", true);
+ WebElement e = getWebElementByXPath("//input[@type='checkbox' and @name='" + checkBoxName + "']", true);
if (!e.isSelected()) {
e.toggle();
}
}
public void checkCheckbox(String checkBoxName, String checkBoxValue) {
- WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "' and @value='" + checkBoxValue + "']", true);
+ WebElement e = getWebElementByXPath("//input[@type='checkbox' and @name='" + checkBoxName + "' and @value='" + checkBoxValue + "']", true);
if (!e.isSelected()) {
e.toggle();
}
}
public void uncheckCheckbox(String checkBoxName) {
- WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "']", true);
+ WebElement e = getWebElementByXPath("//input[@type='checkbox' and @name='" + checkBoxName + "']", true);
if (e.isSelected()) {
e.toggle();
}
}
public void uncheckCheckbox(String checkBoxName, String value) {
- WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "' and @value='" + value + "']", true);
+ WebElement e = getWebElementByXPath("//input[@type='checkbox' and @name='" + checkBoxName + "' and @value='" + value + "']", true);
if (e.isSelected()) {
e.toggle();
}
}
public void clickRadioOption(String radioGroup, String radioOptionValue) {
- WebElement e = getWebElementByXPath("/input[@type='radio' and @name='" + radioGroup + "' and @value='" + radioOptionValue + "']", false);
+ WebElement e = getWebElementByXPath("//input[@type='radio' and @name='" + radioGroup + "' and @value='" + radioOptionValue + "']", false);
e.click();
}
public boolean hasRadioOption(String radioGroup, String radioOptionValue) {
- WebElement e = getWebElementByXPath("/input[@type='radio' and @name='" + radioGroup + "' and @value='" + radioOptionValue + "']", false);
+ WebElement e = getWebElementByXPath("//input[@type='radio' and @name='" + radioGroup + "' and @value='" + radioOptionValue + "']", false);
return e != null;
}
@@ -409,63 +505,67 @@
}
public boolean hasSubmitButton() {
- return (getWebElementByXPath("/input[@type='submit' or @type='image']", true) != null) || (getWebElementByXPath("/button[@type='submit']", false) != null);
+ return (getWebElementByXPath("//input[@type='submit' or @type='image']", true) != null) || (getWebElementByXPath("//button[@type='submit']", false) != null);
}
public boolean hasSubmitButton(String nameOrID) {
- return (getWebElementByXPath("/input[(@type='submit' or @type='image') and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true) != null)
- || (getWebElementByXPath("/button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true) != null);
+ return (getWebElementByXPath("//input[(@type='submit' or @type='image') and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true) != null)
+ || (getWebElementByXPath("//button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true) != null);
}
public boolean hasSubmitButton(String nameOrID, String value) {
- return (getWebElementByXPath("/input[(@type='submit' or @type='image') and (@name='" + nameOrID + "' or @id='" + nameOrID + "') and @value='" + value + "']", true) != null)
- || (getWebElementByXPath("/button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "') and @value='" + value + "']", true) != null);
+ return (getWebElementByXPath("//input[(@type='submit' or @type='image') and (@name='" + nameOrID + "' or @id='" + nameOrID + "') and @value='" + value + "']", true) != null)
+ || (getWebElementByXPath("//button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "') and @value='" + value + "']", true) != null);
}
public void submit() {
- driver.findElement(By.xpath(formSelector())).submit();
+ WebElement e = getWebElementByXPath("//input[@type='submit' or @type='image']", true);
+ if (e == null) {
+ e = getWebElementByXPath("//button[@type='submit']", true);
+ }
+ e.submit();
}
public void submit(String nameOrID) {
- WebElement e = getWebElementByXPath("/input[(@type='submit' or @type='image') and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true);
+ WebElement e = getWebElementByXPath("//input[(@type='submit' or @type='image') and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true);
if (e == null) {
- e = getWebElementByXPath("/button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true);
+ e = getWebElementByXPath("//button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true);
}
e.submit();
}
public void submit(String buttonName, String buttonValue) {
- WebElement e = getWebElementByXPath("/input[(@type='submit' or @type='image') and (@name='" + buttonName + "' or @id='" + buttonName + "') and @value='" + buttonValue + "']", true);
+ WebElement e = getWebElementByXPath("//input[(@type='submit' or @type='image') and (@name='" + buttonName + "' or @id='" + buttonName + "') and @value='" + buttonValue + "']", true);
if (e == null) {
- e = getWebElementByXPath("/button[@type='submit' and (@name='" + buttonName + "' or @id='" + buttonName + "') and @value='" + buttonValue + "']", true);
+ e = getWebElementByXPath("//button[@type='submit' and (@name='" + buttonName + "' or @id='" + buttonName + "') and @value='" + buttonValue + "']", true);
}
e.submit();
}
public boolean hasResetButton() {
- return getWebElementByXPath("/input[@type='reset']", false) != null;
+ return getWebElementByXPath("//input[@type='reset']", false) != null;
}
public boolean hasResetButton(String nameOrID) {
- return getWebElementByXPath("/input[@type='reset' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true) != null;
+ return getWebElementByXPath("//input[@type='reset' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true) != null;
}
public void reset() {
- getWebElementByXPath("/input[@type='reset']", true).click();;
+ getWebElementByXPath("//input[@type='reset']", true).click();;
}
private WebElement getButton(String nameOrID) {
- WebElement e = getWebElementByXPath("/input[(@type='submit' or @type='image' or @type='reset' or @type='button') and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", false);
+ WebElement e = getWebElementByXPath("//input[(@type='submit' or @type='image' or @type='reset' or @type='button') and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", false);
if (e == null) {
- e = getWebElementByXPath("/button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", false);
+ e = getWebElementByXPath("//button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", false);
}
return e;
}
private WebElement getButtonWithText(String text) {
- WebElement e = getWebElementByXPath("/input[(@type='submit' or @type='image' or @type='reset' or @type='button') and contains(.,'" + text + "')]", false);
+ WebElement e = getWebElementByXPath("//input[(@type='submit' or @type='reset' or @type='button') and contains(@value," + escapeQuotes(text) + ")]", false);
if (e == null) {
- e = getWebElementByXPath("/button[@type='submit' and contains(.,'" + text + "')]", false);
+ e = getWebElementByXPath("//button[contains(.," + escapeQuotes(text) + ")]", false);
}
return e;
}
@@ -526,20 +626,56 @@
throw new UnsupportedOperationException("Not supported yet.");
}
+ private WebElement getLinkWithImage(String filename, int index) {
+ try {
+ return driver.findElement(By.xpath("(//a[img[contains(@src,"
+ + escapeQuotes(filename) + ")]])[" + (index + 1) + "]"));
+ } catch (NoSuchElementException e) {
+ return null;
+ }
+ }
+
+ private WebElement getLinkWithText(String linkText, int index) {
+ List<WebElement> lnks = driver.findElements(By.xpath("//a"));
+ int count = 0;
+ for (WebElement lnk : lnks) {
+ if ((lnk.getText().indexOf(linkText) >= 0) && (count++ == index)) {
+ return lnk;
+ }
+ }
+ return null;
+ }
+
+ private WebElement getLinkWithExactText(String linkText, int index) {
+ List<WebElement> lnks = driver.findElements(By.xpath("//a"));
+ int count = 0;
+ for (WebElement lnk : lnks) {
+ if (lnk.getText().equals(linkText) && (count++ == index)) {
+ return lnk;
+ }
+ }
+ return null;
+ }
+
public boolean hasLinkWithText(String linkText, int index) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return getLinkWithText(linkText, index) != null;
}
public boolean hasLinkWithExactText(String linkText, int index) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return getLinkWithExactText(linkText, index) != null;
}
public boolean hasLinkWithImage(String imageFileName, int index) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return getLinkWithImage(imageFileName, index) != null;
}
public boolean hasLink(String anId) {
- return driver.findElement(By.xpath("//a[@id='" + anId + "']")) != null;
+ try {
+ driver.findElement(By.xpath("//a[@id='" + anId + "']"));
+ return true;
+ } catch (NoSuchElementException e) {
+ return false;
+ }
}
public void clickLinkWithText(String linkText, int index) {
@@ -559,7 +695,12 @@
}
public boolean hasElement(String anID) {
- throw new UnsupportedOperationException("Not supported yet.");
+ try {
+ driver.findElement(By.id(anID));
+ return true;
+ } catch (NoSuchElementException e) {
+ return false;
+ }
}
public boolean hasElementByXPath(String xpath) {
@@ -572,26 +713,53 @@
}
public void clickElementByXPath(String xpath) {
- throw new UnsupportedOperationException("Not supported yet.");
+ driver.findElement(By.xpath(xpath)).click();
}
public String getElementAttributByXPath(String xpath, String attribut) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return driver.findElement(By.xpath(xpath)).getAttribute(attribut);
}
public String getElementTextByXPath(String xpath) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return driver.findElement(By.xpath(xpath)).getText();
}
public boolean isTextInElement(String elementID, String text) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return isTextInElement(driver.findElement(By.id(elementID)), text);
}
+ /**
+ * Return true if a given string is contained within the specified element.
+ *
+ * @param element element to inspect.
+ * @param text text to check for.
+ */
+ private boolean isTextInElement(WebElement element, String text) {
+ return element.getText().indexOf(text) >= 0;
+ }
+
public boolean isMatchInElement(String elementID, String regexp) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return isMatchInElement(driver.findElement(By.id(elementID)), regexp);
}
- public void setExpectedJavaScriptAlert(JavascriptAlert[] alerts) throws ExpectedJavascriptAlertException {
+ /**
+ * Return true if a given regexp is contained within the specified element.
+ *
+ * @param element element to inspect.
+ * @param regexp regexp to match.
+ */
+ private boolean isMatchInElement(WebElement element, String regexp) {
+ RE re = getRE(regexp);
+ return re.match(element.getText());
+ }
+
+ private RE getRE(String regexp) {
+ try {
+ return new RE(regexp, RE.MATCH_SINGLELINE);
+ } catch (RESyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ } public void setExpectedJavaScriptAlert(JavascriptAlert[] alerts) throws ExpectedJavascriptAlertException {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -638,4 +806,41 @@
public void setTimeout(int milliseconds) {
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ public List<HttpHeader> getResponseHeaders() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Copied from {@link Select}
+ * @param toEscape
+ * @return
+ */
+ protected String escapeQuotes(String toEscape) {
+ // Convert strings with both quotes and ticks into: foo'"bar -> concat("foo'", '"', "bar")
+ if (toEscape.indexOf("\"") > -1 && toEscape.indexOf("'") > -1) {
+ boolean quoteIsLast = false;
+ if (toEscape.indexOf("\"") == toEscape.length() -1) {
+ quoteIsLast = true;
+ }
+ String[] substrings = toEscape.split("\"");
+
+ StringBuilder quoted = new StringBuilder("concat(");
+ for (int i = 0; i < substrings.length; i++) {
+ quoted.append("\"").append(substrings[i]).append("\"");
+ quoted.append(((i == substrings.length -1) ? (quoteIsLast ? ", '\"')" : ")") : ", '\"', "));
+ }
+ return quoted.toString();
+ }
+
+ // Escape string with just a quote into being single quoted: f"oo -> 'f"oo'
+ if (toEscape.indexOf("\"") > -1) {
+ return String.format("'%s'", toEscape);
+ }
+
+ // Otherwise return the quoted string
+ return String.format("\"%s\"", toEscape);
+ }
+
}
Added: branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebdriverElementImpl.java
===================================================================
--- branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebdriverElementImpl.java (rev 0)
+++ branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebdriverElementImpl.java 2011-03-21 16:20:16 UTC (rev 901)
@@ -0,0 +1,198 @@
+/**
+ * Copyright (c) 2010, JWebUnit team.
+ *
+ * This file is part of JWebUnit.
+ *
+ * JWebUnit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JWebUnit 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 Lesser General Public License
+ * along with JWebUnit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *
+ */
+package net.sourceforge.jwebunit.webdriver;
+
+import org.openqa.selenium.JavascriptExecutor;
+
+import org.openqa.selenium.By;
+
+import org.openqa.selenium.WebElement;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sourceforge.jwebunit.api.IElement;
+
+import com.gargoylesoftware.htmlunit.html.DomNode;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
+
+/**
+ * Webdriver implementation of IElement wrapper.
+ *
+ * @author henryju
+ *
+ */
+public class WebdriverElementImpl implements IElement {
+
+ /**
+ * The wrapped element.
+ */
+ private WebElement element;
+
+ public WebdriverElementImpl(WebElement element) {
+ if (element == null)
+ throw new NullPointerException("Cannot create an IElement for a null element.");
+ this.element = element;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#attribute(java.lang.String)
+ */
+ public String getAttribute(String name) {
+ return element.getAttribute(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#name()
+ */
+ public String getName() {
+ return element.getTagName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#getChildren()
+ */
+ public List<IElement> getChildren() {
+ List<IElement> children = new ArrayList<IElement>();
+ for (WebElement e : element.findElements(By.xpath("/"))) {
+ if (e != null)
+ children.add(new WebdriverElementImpl(e));
+ }
+ return children;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#getParent()
+ */
+ public IElement getParent() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#getTextContent()
+ */
+ public String getTextContent() {
+ return element.getText();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#getElement(java.lang.String)
+ */
+ public IElement getElement(String xpath) {
+ return new WebdriverElementImpl((WebElement) element.findElement(By.xpath(xpath)));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#getElements(java.lang.String)
+ */
+ public List<IElement> getElements(String xpath) {
+ List<IElement> elements = new ArrayList<IElement>();
+ for (WebElement o : element.findElements(By.xpath(xpath))) {
+ elements.add(new WebdriverElementImpl(o));
+ }
+ return elements;
+ }
+
+ public String toString() {
+ return "IElement[name=" + getName() + " wrapped=" + element + "]";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#setAttribute(java.lang.String)
+ */
+ public void setAttribute(String string) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#setAttribute(java.lang.String, java.lang.String)
+ */
+ public void setAttribute(String string, String value) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.jwebunit.api.IElement#setTextContent(java.lang.String)
+ */
+ public void setTextContent(String value) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 37;
+ int result = 1;
+ result = prime * result + ((element == null) ? 0 : element.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final WebdriverElementImpl other = (WebdriverElementImpl) obj;
+ if (element == null) {
+ if (other.element != null)
+ return false;
+ }
+ else if (!element.equals(other.element))
+ return false;
+ return true;
+ }
+
+ /**
+ * Return the unwrapped Webdriver element that this IElement represents.
+ *
+ * @return the Webdriver element this IElement represents.
+ */
+ public WebElement getHtmlElement() {
+ return element;
+ }
+
+}
Property changes on: branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebdriverElementImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/webdriver/JWebUnitTest.java
===================================================================
--- branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/webdriver/JWebUnitTest.java 2011-03-18 22:07:48 UTC (rev 900)
+++ branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/webdriver/JWebUnitTest.java 2011-03-21 16:20:16 UTC (rev 901)
@@ -19,58 +19,70 @@
package net.sourceforge.jwebunit.webdriver;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import net.sourceforge.jwebunit.tests.ButtonAssertionsTest;
+import net.sourceforge.jwebunit.tests.CharsetTest;
+import net.sourceforge.jwebunit.tests.CustomTesterTest;
+import net.sourceforge.jwebunit.tests.ExpectedTableAssertionsHtmlTest;
+import net.sourceforge.jwebunit.tests.ExpectedTableAssertionsXHtmlTest;
+import net.sourceforge.jwebunit.tests.FormAssertionsTest;
+import net.sourceforge.jwebunit.tests.FormSubmissionTest;
+import net.sourceforge.jwebunit.tests.FramesAndWindowsTest;
+import net.sourceforge.jwebunit.tests.HelloWorldTest;
+import net.sourceforge.jwebunit.tests.HtmlParsingTest;
+import net.sourceforge.jwebunit.tests.IElementTest;
+import net.sourceforge.jwebunit.tests.ImageTest;
+import net.sourceforge.jwebunit.tests.JUnitPerfTest;
+import net.sourceforge.jwebunit.tests.JavaScriptEventsTest;
+import net.sourceforge.jwebunit.tests.JavaScriptTest;
+import net.sourceforge.jwebunit.tests.NavigationTest;
+import net.sourceforge.jwebunit.tests.NonHtmlContentTest;
+import net.sourceforge.jwebunit.tests.RedirectionTest;
+import net.sourceforge.jwebunit.tests.ResourceBundleAssertionsTest;
+import net.sourceforge.jwebunit.tests.ResponseServletTest;
+import net.sourceforge.jwebunit.tests.SelectOptionsTest;
+import net.sourceforge.jwebunit.tests.TableAssertionsTest;
+import net.sourceforge.jwebunit.tests.TestContextTest;
+import net.sourceforge.jwebunit.tests.WebAssertionsTest;
+import net.sourceforge.jwebunit.tests.WebCookieTest;
+import net.sourceforge.jwebunit.tests.XPathTest;
import net.sourceforge.jwebunit.tests.util.JettySetup;
-import net.sourceforge.jwebunit.tests.*;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Test Suite for JWebUnit.
*
* @author Julien Henry
*/
-public class JWebUnitTest extends TestCase {
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ FormSubmissionTest.class,
+ WebAssertionsTest.class,
+ FramesAndWindowsTest.class,
+ TableAssertionsTest.class,
+ ExpectedTableAssertionsHtmlTest.class,
+ ExpectedTableAssertionsXHtmlTest.class,
+ JavaScriptEventsTest.class,
+ JavaScriptTest.class,
+ HelloWorldTest.class,
+ HtmlParsingTest.class,
+ WebCookieTest.class,
+ TestContextTest.class,
+ FormAssertionsTest.class,
+ NavigationTest.class,
+ XPathTest.class,
+ CharsetTest.class,
+ ButtonAssertionsTest.class,
+ NonHtmlContentTest.class,
+ RedirectionTest.class,
+ ImageTest.class,
+ ResourceBundleAssertionsTest.class,
+ SelectOptionsTest.class,
+ IElementTest.class,
+ ResponseServletTest.class,
+ CustomTesterTest.class,
+ JUnitPerfTest.class
+})
+public class JWebUnitTest extends JettySetup {
- /**
- * Runs all the tests for JWebUnit. Add each new TestCase by using the <code>addTestSuite(Class)</code> method, so
- * that the TestCase's <code>suite</code> method <strong>isn't called </strong>. This prevents
- * <code>JettySetup</code> from starting the Jetty server twice and consequently the error 'port 80xx is already
- * in use'.
- *
- * @return the <code>TestSuite</code> containing all the tests for JWebUnit ready to run utilizing Jetty as
- * testserver.
- */
- public static Test suite() {
- TestSuite suite = new TestSuite("Test for net.sourceforge.jwebunit");
- // $JUnit-BEGIN$
- suite.addTestSuite(FormSubmissionTest.class);
- suite.addTestSuite(WebAssertionsTest.class);
- suite.addTestSuite(FramesAndWindowsTest.class);
- suite.addTestSuite(TableAssertionsTest.class);
- suite.addTestSuite(ExpectedTableAssertionsHtmlTest.class);
- suite.addTestSuite(ExpectedTableAssertionsXHtmlTest.class);
- suite.addTestSuite(JavaScriptEventsTest.class);
- suite.addTestSuite(JavaScriptTest.class);
- suite.addTestSuite(HelloWorldTest.class);
- suite.addTestSuite(HtmlParsingTest.class);
- suite.addTestSuite(WebCookieTest.class);
- suite.addTestSuite(TestContextTest.class);
- suite.addTestSuite(FormAssertionsTest.class);
- suite.addTestSuite(NavigationTest.class);
- suite.addTestSuite(XPathTest.class);
- suite.addTestSuite(CharsetTest.class);
- suite.addTestSuite(ButtonAssertionsTest.class);
- suite.addTestSuite(NonHtmlContentTest.class);
- suite.addTestSuite(RedirectionTest.class);
- suite.addTestSuite(ImageTest.class);
- suite.addTestSuite(ResourceBundleAssertionsTest.class);
- suite.addTestSuite(IElementTest.class);
- suite.addTestSuite(ResponseServletTest.class);
- suite.addTestSuite(CustomTesterTest.class);
- //suite.addTest(JUnitPerfTest.suite());
- // $JUnit-END$
- return new JettySetup(suite);
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2011-03-18 22:07:55
|
Revision: 900
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=900&view=rev
Author: henryju
Date: 2011-03-18 22:07:48 +0000 (Fri, 18 Mar 2011)
Log Message:
-----------
Commit of existing work (several months old).
Modified Paths:
--------------
branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/ParamsServlet.java
branches/webdriver/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
branches/webdriver/jwebunit-core/src/main/java/net/sourceforge/jwebunit/util/TestingEngineRegistry.java
branches/webdriver/pom.xml
Added Paths:
-----------
branches/webdriver/jwebunit-webdriver-plugin/
branches/webdriver/jwebunit-webdriver-plugin/src/
branches/webdriver/jwebunit-webdriver-plugin/src/main/
branches/webdriver/jwebunit-webdriver-plugin/src/main/java/
branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/
branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/
branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/
branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/
branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebDriverTestingEngineImpl.java
branches/webdriver/jwebunit-webdriver-plugin/src/main/resources/
branches/webdriver/jwebunit-webdriver-plugin/src/site/
branches/webdriver/jwebunit-webdriver-plugin/src/site/site.xml
branches/webdriver/jwebunit-webdriver-plugin/src/site/xdoc/
branches/webdriver/jwebunit-webdriver-plugin/src/site/xdoc/index.xml
branches/webdriver/jwebunit-webdriver-plugin/src/test/
branches/webdriver/jwebunit-webdriver-plugin/src/test/java/
branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/
branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/
branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/
branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/webdriver/
branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/webdriver/JWebUnitTest.java
Modified: branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/ParamsServlet.java
===================================================================
--- branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/ParamsServlet.java 2011-03-18 22:05:06 UTC (rev 899)
+++ branches/webdriver/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/ParamsServlet.java 2011-03-18 22:07:48 UTC (rev 900)
@@ -95,7 +95,7 @@
out.write("<br/>\n");
}
}
- out.write(" </p>\n");
+ out.write("</p>\n");
out.write(HtmlHelper.getLinkParagraph("return", ref));
} else {
java.util.Enumeration params = request.getParameterNames();
@@ -114,7 +114,7 @@
out.write("<br/>\n");
}
}
- out.write(" </p>\n");
+ out.write("</p>\n");
String ref = request.getHeader("Referer");
if (ref == null) {
if (request.getParameterValues("myReferer") != null) {
Modified: branches/webdriver/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
===================================================================
--- branches/webdriver/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java 2011-03-18 22:05:06 UTC (rev 899)
+++ branches/webdriver/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java 2011-03-18 22:07:48 UTC (rev 900)
@@ -95,7 +95,7 @@
*
* @return List of javax.servlet.http.Cookie.
*/
- List<?> getCookies();
+ List<javax.servlet.http.Cookie> getCookies();
/**
* Test if the window with the given name is present.
Modified: branches/webdriver/jwebunit-core/src/main/java/net/sourceforge/jwebunit/util/TestingEngineRegistry.java
===================================================================
--- branches/webdriver/jwebunit-core/src/main/java/net/sourceforge/jwebunit/util/TestingEngineRegistry.java 2011-03-18 22:05:06 UTC (rev 899)
+++ branches/webdriver/jwebunit-core/src/main/java/net/sourceforge/jwebunit/util/TestingEngineRegistry.java 2011-03-18 22:07:48 UTC (rev 900)
@@ -37,10 +37,15 @@
public final static String TESTING_ENGINE_HTMLUNIT = "TestingEngineHtmlUnit";
/**
- * Key of HtmlUnit testing engine.
+ * Key of Selenium testing engine.
*/
public final static String TESTING_ENGINE_SELENIUM = "TestingEngineSelenium";
+ /**
+ * Key of Selenium testing engine.
+ */
+ public final static String TESTING_ENGINE_WEBDRIVER = "TestingEngineWebDriver";
+
private static Hashtable<String,Class<?>> testingEngineMap = new Hashtable<String,Class<?>>();
static {
@@ -58,6 +63,13 @@
} catch (ClassNotFoundException e) {
// Selenium Testing Engine is not present in the classpath. Nothing to do.
}
+ cp = "net.sourceforge.jwebunit.webdriver.WebDriverTestingEngineImpl";
+ // Try to load WebDriver Testing Engine to check if it is present.
+ try {
+ addTestingEngine(TESTING_ENGINE_WEBDRIVER, cp);
+ } catch (ClassNotFoundException e) {
+ // WebDriver Testing Engine is not present in the classpath. Nothing to do.
+ }
}
/**
Property changes on: branches/webdriver/jwebunit-webdriver-plugin
___________________________________________________________________
Added: svn:ignore
+ target
Added: branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebDriverTestingEngineImpl.java
===================================================================
--- branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebDriverTestingEngineImpl.java (rev 0)
+++ branches/webdriver/jwebunit-webdriver-plugin/src/main/java/net/sourceforge/jwebunit/webdriver/WebDriverTestingEngineImpl.java 2011-03-18 22:07:48 UTC (rev 900)
@@ -0,0 +1,641 @@
+/**
+ * Copyright (c) 2010, JWebUnit team.
+ *
+ * This file is part of JWebUnit.
+ *
+ * JWebUnit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JWebUnit 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 Lesser General Public License
+ * along with JWebUnit. If not, see <http://www.gnu.org/licenses/>.
+ */
+package net.sourceforge.jwebunit.webdriver;
+
+import com.gargoylesoftware.htmlunit.BrowserVersion;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+
+import net.sourceforge.jwebunit.api.IElement;
+import net.sourceforge.jwebunit.api.ITestingEngine;
+import net.sourceforge.jwebunit.exception.ExpectedJavascriptAlertException;
+import net.sourceforge.jwebunit.exception.ExpectedJavascriptConfirmException;
+import net.sourceforge.jwebunit.exception.ExpectedJavascriptPromptException;
+import net.sourceforge.jwebunit.exception.TestingEngineResponseException;
+import net.sourceforge.jwebunit.html.Table;
+import net.sourceforge.jwebunit.javascript.JavascriptAlert;
+import net.sourceforge.jwebunit.javascript.JavascriptConfirm;
+import net.sourceforge.jwebunit.javascript.JavascriptPrompt;
+import net.sourceforge.jwebunit.util.TestContext;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Cookie;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.NoSuchWindowException;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.htmlunit.HtmlUnitDriver;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Acts as the wrapper for Webdriver access. A testing engine is initialized with a given URL, and maintains
+ * conversational state as the dialog progresses through link navigation, form submission, etc.
+ *
+ * @author Julien Henry
+ */
+public class WebDriverTestingEngineImpl implements ITestingEngine {
+
+ /**
+ * Logger for this class.
+ */
+ private final Logger logger = LoggerFactory.getLogger(WebDriverTestingEngineImpl.class);
+ private WebDriver driver;
+ private TestContext testContext;
+ // The xpath string that identifie the current form
+ // ie : @name='myForm'
+ private String formIdent;
+
+ public WebDriverTestingEngineImpl() {
+ }
+
+ public void beginAt(URL aInitialURL, TestContext aTestContext) throws TestingEngineResponseException {
+ this.setTestContext(aTestContext);
+ driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3);
+
+ gotoPage(aInitialURL);
+ }
+
+ public void setTestContext(TestContext testContext) {
+ this.testContext = testContext;
+ }
+
+ public void closeBrowser() throws ExpectedJavascriptAlertException, ExpectedJavascriptConfirmException, ExpectedJavascriptPromptException {
+ driver.close();
+ }
+
+ public void gotoPage(URL url) throws TestingEngineResponseException {
+ driver.get(url.toString());
+ }
+
+ public void setScriptingEnabled(boolean value) {
+ if (driver instanceof HtmlUnitDriver) {
+ ((HtmlUnitDriver) driver).setJavascriptEnabled(value);
+ }
+ }
+
+ public void setThrowExceptionOnScriptError(boolean value) {
+ }
+
+ public List<javax.servlet.http.Cookie> getCookies() {
+ List<javax.servlet.http.Cookie> result = new LinkedList<javax.servlet.http.Cookie>();
+ Set<Cookie> cookies = driver.manage().getCookies();
+ for (Cookie cookie : cookies) {
+ javax.servlet.http.Cookie c = new javax.servlet.http.Cookie(
+ cookie.getName(), cookie.getValue());
+ c.setDomain(cookie.getDomain());
+ Date expire = cookie.getExpiry();
+ if (expire == null) {
+ c.setMaxAge(-1);
+ } else {
+ Date now = Calendar.getInstance().getTime();
+ // Convert milli-second to second
+ Long second = Long.valueOf((expire.getTime() - now.getTime()) / 1000);
+ c.setMaxAge(second.intValue());
+ }
+ c.setPath(cookie.getPath());
+ c.setSecure(cookie.isSecure());
+ result.add(c);
+ }
+ return result;
+ }
+
+ public boolean hasWindow(String windowName) {
+ //Save current handle
+ String current = driver.getWindowHandle();
+ try {
+ driver.switchTo().window(windowName);
+ driver.switchTo().window(current);
+ return true;
+ } catch (NoSuchWindowException e) {
+ return false;
+ }
+ }
+
+ public boolean hasWindowByTitle(String windowTitle) {
+ //Save current handle
+ String current = driver.getWindowHandle();
+ for (String handle : driver.getWindowHandles()) {
+ driver.switchTo().window(handle);
+ if (driver.getTitle().equals(windowTitle)) {
+ driver.switchTo().window(current);
+ return true;
+ }
+ }
+ driver.switchTo().window(current);
+ return false;
+ }
+
+ public void gotoWindow(String windowName) {
+ driver.switchTo().window(windowName);
+ }
+
+ public void gotoWindowByTitle(String title) {
+ //Save current handle
+ String current = driver.getWindowHandle();
+ for (String handle : driver.getWindowHandles()) {
+ driver.switchTo().window(handle);
+ if (driver.getTitle().equals(title)) {
+ return;
+ }
+ }
+ driver.switchTo().window(current);
+ }
+
+ public void gotoWindow(int windowID) {
+ driver.switchTo().window("" + windowID);
+ }
+
+ public void gotoRootWindow() {
+ driver.switchTo().window("top");
+ }
+
+ public int getWindowCount() {
+ return driver.getWindowHandles().size();
+ }
+
+ public void closeWindow() {
+ driver.close();
+ }
+
+ public boolean hasFrame(String frameNameOrId) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void gotoFrame(String frameNameOrId) {
+ driver.switchTo().frame(frameNameOrId);
+ }
+
+ public void setWorkingForm(int index) {
+ formIdent = "position()=" + (index + 1);
+ }
+
+ public void setWorkingForm(String nameOrId, int index) {
+ if (nameOrId != null) {
+ formIdent = "(@name='" + nameOrId + "' or @id='" + nameOrId + "')][position()="
+ + (index + 1);
+ } else {
+ formIdent = null;
+ }
+ }
+
+ protected String formSelector() {
+ if (formIdent == null) {
+ return "//form";
+ }
+ return "//form[" + formIdent + "]";
+ }
+
+ public boolean hasForm() {
+ return hasElementByXPath("//form");
+ }
+
+ public boolean hasForm(String nameOrID) {
+ return hasElementByXPath("//form[@name='" + nameOrID + "' or @id='" + nameOrID + "']");
+ }
+
+ public boolean hasFormParameterNamed(String paramName) {
+ return hasElementByXPath(formSelector() + "//*[@name='" + paramName + "']");
+ }
+
+ private WebElement getWebElementByXPath(String xpathAfterForm, boolean onlyInCurrentForm) {
+ //First try the current form
+ if (formIdent != null) {
+ try {
+ return driver.findElement(By.xpath("//form[" + formIdent + "]" + xpathAfterForm));
+ } catch (NoSuchElementException ex) {
+ if (onlyInCurrentForm) {
+ return null;
+ }
+ }
+ }
+ // not in the current form: try other forms
+ List<WebElement> forms = driver.findElements(By.tagName("form"));
+ int index = 0;
+ for (WebElement f : forms) {
+ try {
+ WebElement e = driver.findElement(By.xpath("//form[position()=" + (index + 1) + "]" + xpathAfterForm));
+ setWorkingForm(index);
+ return e;
+ } catch (NoSuchElementException ex) {
+ index ++;
+ }
+ }
+ // now look everywhere (maybe outside of form)
+ try {
+ return driver.findElement(By.xpath("//body" + xpathAfterForm));
+ } catch (NoSuchElementException ex) {
+ return null;
+ }
+ }
+
+ private List<WebElement> getWebElementsByXPath(String xpathAfterForm) {
+ try {
+ return driver.findElements(By.xpath(formSelector() + xpathAfterForm));
+ } catch (NoSuchElementException e) {
+ return null;
+ }
+ }
+
+ public String getTextFieldValue(String paramName) {
+ WebElement e = getWebElementByXPath("/input[@type='text' and @name='" + paramName + "']", false);
+ return e.getValue();
+ }
+
+ public String getHiddenFieldValue(String paramName) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void setTextField(String inputName, String text) {
+ WebElement e = getWebElementByXPath("/input[@type='text' and @name='" + inputName + "']", false);
+ if (e == null) {
+ e = getWebElementByXPath("/textarea[@name='" + inputName + "']", false);
+ }
+ if (e == null) {
+ e = getWebElementByXPath("/input[@type='file' and @name='" + inputName + "']", false);
+ }
+ e.clear();
+ e.sendKeys(text);
+ }
+
+ public void setHiddenField(String inputName, String text) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getSelectOptionValues(String selectName) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getSelectOptionValues(String selectName, int index) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getSelectedOptions(String selectName) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getSelectedOptions(String selectName, int index) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getSelectOptionLabelForValue(String selectName, String optionValue) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getSelectOptionLabelForValue(String selectName, int index, String optionValue) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getSelectOptionValueForLabel(String selectName, String optionLabel) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getSelectOptionValueForLabel(String selectName, int index, String optionLabel) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void selectOptions(String selectName, String[] optionValues) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void selectOptions(String selectName, int index, String[] optionValues) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void unselectOptions(String selectName, String[] optionValues) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void unselectOptions(String selectName, int index, String[] optionValues) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasSelectOption(String selectName, String optionLabel) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasSelectOptionValue(String selectName, String optionValue) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasSelectOption(String selectName, int index, String optionLabel) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasSelectOptionValue(String selectName, int index, String optionValue) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isCheckboxSelected(String checkBoxName) {
+ WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "']", true);
+ return e.isSelected();
+ }
+
+ public boolean isCheckboxSelected(String checkBoxName, String checkBoxValue) {
+ WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "' and @value='" + checkBoxValue + "']", true);
+ return e.isSelected();
+ }
+
+ public void checkCheckbox(String checkBoxName) {
+ WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "']", true);
+ if (!e.isSelected()) {
+ e.toggle();
+ }
+ }
+
+ public void checkCheckbox(String checkBoxName, String checkBoxValue) {
+ WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "' and @value='" + checkBoxValue + "']", true);
+ if (!e.isSelected()) {
+ e.toggle();
+ }
+ }
+
+ public void uncheckCheckbox(String checkBoxName) {
+ WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "']", true);
+ if (e.isSelected()) {
+ e.toggle();
+ }
+ }
+
+ public void uncheckCheckbox(String checkBoxName, String value) {
+ WebElement e = getWebElementByXPath("/input[@type='checkbox' and @name='" + checkBoxName + "' and @value='" + value + "']", true);
+ if (e.isSelected()) {
+ e.toggle();
+ }
+ }
+
+ public void clickRadioOption(String radioGroup, String radioOptionValue) {
+ WebElement e = getWebElementByXPath("/input[@type='radio' and @name='" + radioGroup + "' and @value='" + radioOptionValue + "']", false);
+ e.click();
+ }
+
+ public boolean hasRadioOption(String radioGroup, String radioOptionValue) {
+ WebElement e = getWebElementByXPath("/input[@type='radio' and @name='" + radioGroup + "' and @value='" + radioOptionValue + "']", false);
+ return e != null;
+ }
+
+ public String getSelectedRadio(String radioGroup) {
+ List<WebElement> radios = getWebElementsByXPath("/input[@type='radio' and @name='" + radioGroup + "']");
+ for (WebElement r : radios) {
+ if (r.isSelected()) {
+ return r.getValue();
+ }
+ }
+ return null;
+ }
+
+ public boolean hasSubmitButton() {
+ return (getWebElementByXPath("/input[@type='submit' or @type='image']", true) != null) || (getWebElementByXPath("/button[@type='submit']", false) != null);
+ }
+
+ public boolean hasSubmitButton(String nameOrID) {
+ return (getWebElementByXPath("/input[(@type='submit' or @type='image') and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true) != null)
+ || (getWebElementByXPath("/button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true) != null);
+ }
+
+ public boolean hasSubmitButton(String nameOrID, String value) {
+ return (getWebElementByXPath("/input[(@type='submit' or @type='image') and (@name='" + nameOrID + "' or @id='" + nameOrID + "') and @value='" + value + "']", true) != null)
+ || (getWebElementByXPath("/button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "') and @value='" + value + "']", true) != null);
+ }
+
+ public void submit() {
+ driver.findElement(By.xpath(formSelector())).submit();
+ }
+
+ public void submit(String nameOrID) {
+ WebElement e = getWebElementByXPath("/input[(@type='submit' or @type='image') and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true);
+ if (e == null) {
+ e = getWebElementByXPath("/button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true);
+ }
+ e.submit();
+ }
+
+ public void submit(String buttonName, String buttonValue) {
+ WebElement e = getWebElementByXPath("/input[(@type='submit' or @type='image') and (@name='" + buttonName + "' or @id='" + buttonName + "') and @value='" + buttonValue + "']", true);
+ if (e == null) {
+ e = getWebElementByXPath("/button[@type='submit' and (@name='" + buttonName + "' or @id='" + buttonName + "') and @value='" + buttonValue + "']", true);
+ }
+ e.submit();
+ }
+
+ public boolean hasResetButton() {
+ return getWebElementByXPath("/input[@type='reset']", false) != null;
+ }
+
+ public boolean hasResetButton(String nameOrID) {
+ return getWebElementByXPath("/input[@type='reset' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", true) != null;
+ }
+
+ public void reset() {
+ getWebElementByXPath("/input[@type='reset']", true).click();;
+ }
+
+ private WebElement getButton(String nameOrID) {
+ WebElement e = getWebElementByXPath("/input[(@type='submit' or @type='image' or @type='reset' or @type='button') and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", false);
+ if (e == null) {
+ e = getWebElementByXPath("/button[@type='submit' and (@name='" + nameOrID + "' or @id='" + nameOrID + "')]", false);
+ }
+ return e;
+ }
+
+ private WebElement getButtonWithText(String text) {
+ WebElement e = getWebElementByXPath("/input[(@type='submit' or @type='image' or @type='reset' or @type='button') and contains(.,'" + text + "')]", false);
+ if (e == null) {
+ e = getWebElementByXPath("/button[@type='submit' and contains(.,'" + text + "')]", false);
+ }
+ return e;
+ }
+
+ public boolean hasButtonWithText(String text) {
+ return getButtonWithText(text) != null;
+ }
+
+ public boolean hasButton(String buttonId) {
+ return getButton(buttonId) != null;
+ }
+
+ public void clickButton(String buttonId) {
+ getButton(buttonId).click();
+ }
+
+ public void clickButtonWithText(String buttonValueText) {
+ getButtonWithText(buttonValueText).click();
+ }
+
+ public URL getPageURL() {
+ try {
+ return new URL(driver.getCurrentUrl());
+ } catch (MalformedURLException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public String getPageText() {
+ return driver.findElement(By.xpath("//body")).getText();
+ }
+
+ public String getPageSource() {
+ return driver.getPageSource();
+ }
+
+ public String getPageTitle() {
+ return driver.getTitle();
+ }
+
+ public String getServerResponse() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public InputStream getInputStream() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public InputStream getInputStream(URL url) throws TestingEngineResponseException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasTable(String tableSummaryNameOrId) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Table getTable(String tableSummaryNameOrId) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasLinkWithText(String linkText, int index) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasLinkWithExactText(String linkText, int index) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasLinkWithImage(String imageFileName, int index) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasLink(String anId) {
+ return driver.findElement(By.xpath("//a[@id='" + anId + "']")) != null;
+ }
+
+ public void clickLinkWithText(String linkText, int index) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void clickLinkWithExactText(String linkText, int index) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void clickLink(String anID) {
+ driver.findElement(By.xpath("//a[@id='" + anID + "']")).click();
+ }
+
+ public void clickLinkWithImage(String imageFileName, int index) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasElement(String anID) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasElementByXPath(String xpath) {
+ try {
+ driver.findElement(By.xpath(xpath));
+ return true;
+ } catch (NoSuchElementException e) {
+ return false;
+ }
+ }
+
+ public void clickElementByXPath(String xpath) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getElementAttributByXPath(String xpath, String attribut) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getElementTextByXPath(String xpath) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isTextInElement(String elementID, String text) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isMatchInElement(String elementID, String regexp) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void setExpectedJavaScriptAlert(JavascriptAlert[] alerts) throws ExpectedJavascriptAlertException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void setExpectedJavaScriptConfirm(JavascriptConfirm[] confirms) throws ExpectedJavascriptConfirmException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts) throws ExpectedJavascriptPromptException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public IElement getElementByXPath(String xpath) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public IElement getElementByID(String id) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public List<IElement> getElementsByXPath(String xpath) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public int getServerResponseCode() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getHeader(String name) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Map<String, String> getAllHeaders() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void setIgnoreFailingStatusCodes(boolean ignore) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public List<String> getComments() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void setTimeout(int milliseconds) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+}
Added: branches/webdriver/jwebunit-webdriver-plugin/src/site/site.xml
===================================================================
--- branches/webdriver/jwebunit-webdriver-plugin/src/site/site.xml (rev 0)
+++ branches/webdriver/jwebunit-webdriver-plugin/src/site/site.xml 2011-03-18 22:07:48 UTC (rev 900)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+
+ Copyright (c) 2010, JWebUnit team.
+
+ This file is part of JWebUnit.
+
+ JWebUnit is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ JWebUnit 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 Lesser General Public License
+ along with JWebUnit. If not, see <http://www.gnu.org/licenses/>.
+
+-->
+
+<project name="JWebUnit">
+ <body>
+ <menu ref="reports" />
+ </body>
+</project>
Added: branches/webdriver/jwebunit-webdriver-plugin/src/site/xdoc/index.xml
===================================================================
--- branches/webdriver/jwebunit-webdriver-plugin/src/site/xdoc/index.xml (rev 0)
+++ branches/webdriver/jwebunit-webdriver-plugin/src/site/xdoc/index.xml 2011-03-18 22:07:48 UTC (rev 900)
@@ -0,0 +1,61 @@
+<?xml version="1.0"?>
+<!--
+
+ Copyright (c) 2010, JWebUnit team.
+
+ This file is part of JWebUnit.
+
+ JWebUnit is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ JWebUnit 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 Lesser General Public License
+ along with JWebUnit. If not, see <http://www.gnu.org/licenses/>.
+
+-->
+
+<document>
+ <properties>
+ <author email="henryju.at.users.sourceforge.net">Julien HENRY</author>
+ <title>JWebUnit</title>
+ </properties>
+ <meta name="keyword" content="jwebunit, java, junit, htmlunit, jacobie, httpunit, integration, test, automated, html, webtest, selenium"/>
+ <head>
+ <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
+ </head>
+<body>
+<section name="Selenium plugin">
+ <p>
+ The Selenium plugin allow to run your test in a real browser. The main advantage is the JavaScript support is perfectly identical to
+ your target browser (of course). The main drawbacks are it is slooooooow and can't run on a headless server.
+ </p>
+ <p>
+ This plugin is still in development. In fact not all test cases works. Feel free to <a href="../how-to-contribute.html">contribute</a>
+ </p>
+</section>
+<section name="HowTo manage dependencies with Maven 2">
+ <p>
+ Just add the following dependency to your pom:
+ <source><pre>
+...
+<dependencies>
+ ...
+ <dependency>
+ <groupId>net.sourceforge.jwebunit</groupId>
+ <artifactId>jwebunit-selenium-plugin</artifactId>
+ <version>2.0</version>
+ </dependency>
+ ...
+</dependencies>
+...
+ </pre></source>
+ </p>
+</section>
+</body>
+</document>
Added: branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/webdriver/JWebUnitTest.java
===================================================================
--- branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/webdriver/JWebUnitTest.java (rev 0)
+++ branches/webdriver/jwebunit-webdriver-plugin/src/test/java/net/sourceforge/jwebunit/webdriver/JWebUnitTest.java 2011-03-18 22:07:48 UTC (rev 900)
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2010, JWebUnit team.
+ *
+ * This file is part of JWebUnit.
+ *
+ * JWebUnit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JWebUnit 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 Lesser General Public License
+ * along with JWebUnit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.sourceforge.jwebunit.webdriver;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import net.sourceforge.jwebunit.tests.util.JettySetup;
+import net.sourceforge.jwebunit.tests.*;
+
+/**
+ * Test Suite for JWebUnit.
+ *
+ * @author Julien Henry
+ */
+public class JWebUnitTest extends TestCase {
+
+ /**
+ * Runs all the tests for JWebUnit. Add each new TestCase by using the <code>addTestSuite(Class)</code> method, so
+ * that the TestCase's <code>suite</code> method <strong>isn't called </strong>. This prevents
+ * <code>JettySetup</code> from starting the Jetty server twice and consequently the error 'port 80xx is already
+ * in use'.
+ *
+ * @return the <code>TestSuite</code> containing all the tests for JWebUnit ready to run utilizing Jetty as
+ * testserver.
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for net.sourceforge.jwebunit");
+ // $JUnit-BEGIN$
+ suite.addTestSuite(FormSubmissionTest.class);
+ suite.addTestSuite(WebAssertionsTest.class);
+ suite.addTestSuite(FramesAndWindowsTest.class);
+ suite.addTestSuite(TableAssertionsTest.class);
+ suite.addTestSuite(ExpectedTableAssertionsHtmlTest.class);
+ suite.addTestSuite(ExpectedTableAssertionsXHtmlTest.class);
+ suite.addTestSuite(JavaScriptEventsTest.class);
+ suite.addTestSuite(JavaScriptTest.class);
+ suite.addTestSuite(HelloWorldTest.class);
+ suite.addTestSuite(HtmlParsingTest.class);
+ suite.addTestSuite(WebCookieTest.class);
+ suite.addTestSuite(TestContextTest.class);
+ suite.addTestSuite(FormAssertionsTest.class);
+ suite.addTestSuite(NavigationTest.class);
+ suite.addTestSuite(XPathTest.class);
+ suite.addTestSuite(CharsetTest.class);
+ suite.addTestSuite(ButtonAssertionsTest.class);
+ suite.addTestSuite(NonHtmlContentTest.class);
+ suite.addTestSuite(RedirectionTest.class);
+ suite.addTestSuite(ImageTest.class);
+ suite.addTestSuite(ResourceBundleAssertionsTest.class);
+ suite.addTestSuite(IElementTest.class);
+ suite.addTestSuite(ResponseServletTest.class);
+ suite.addTestSuite(CustomTesterTest.class);
+ //suite.addTest(JUnitPerfTest.suite());
+ // $JUnit-END$
+ return new JettySetup(suite);
+ }
+
+}
Modified: branches/webdriver/pom.xml
===================================================================
--- branches/webdriver/pom.xml 2011-03-18 22:05:06 UTC (rev 899)
+++ branches/webdriver/pom.xml 2011-03-18 22:07:48 UTC (rev 900)
@@ -26,6 +26,7 @@
<module>jwebunit-commons-tests</module>
<module>jwebunit-htmlunit-plugin</module>
<module>jwebunit-selenium-plugin</module>
+ <module>jwebunit-webdriver-plugin</module>
</modules>
<mailingLists>
<mailingList>
@@ -407,6 +408,11 @@
<version>1.0.2</version>
</dependency>
<dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-htmlunit-driver</artifactId>
+ <version>2.0a5</version>
+ </dependency>
+ <dependency>
<groupId>regexp</groupId>
<artifactId>regexp</artifactId>
<version>1.3</version>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2011-03-18 22:05:13
|
Revision: 899
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=899&view=rev
Author: henryju
Date: 2011-03-18 22:05:06 +0000 (Fri, 18 Mar 2011)
Log Message:
-----------
Create a branch to work on webdriver testing engine.
Added Paths:
-----------
branches/webdriver/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2011-03-16 09:23:26
|
Revision: 898
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=898&view=rev
Author: henryju
Date: 2011-03-16 09:23:19 +0000 (Wed, 16 Mar 2011)
Log Message:
-----------
Updated some plugins. Migrated from Jetty 6 to Jetty 6.
Modified Paths:
--------------
trunk/jwebunit-commons-tests/pom.xml
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebCookieTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/CookiesServlet.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/JettySetup.java
trunk/jwebunit-commons-tests/src/main/resources/logback-test.xml
trunk/pom.xml
Added Paths:
-----------
trunk/jwebunit-commons-tests/src/main/resources/jetty-users.properties
Modified: trunk/jwebunit-commons-tests/pom.xml
===================================================================
--- trunk/jwebunit-commons-tests/pom.xml 2011-03-14 11:11:36 UTC (rev 897)
+++ trunk/jwebunit-commons-tests/pom.xml 2011-03-16 09:23:19 UTC (rev 898)
@@ -19,8 +19,8 @@
<artifactId>hamcrest-library</artifactId>
</dependency>
<dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.jwebunit</groupId>
Modified: trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebCookieTest.java
===================================================================
--- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebCookieTest.java 2011-03-14 11:11:36 UTC (rev 897)
+++ trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebCookieTest.java 2011-03-16 09:23:19 UTC (rev 898)
@@ -88,8 +88,8 @@
*/
@Test
public void testCookieMatchLastCookie() {
- beginAt("/cookies.jsp?threesamecookies=true&dont_set=1");
- assertCookieValueMatch("JSESSIONID", "(.)*worker3");
+ beginAt("/cookies.jsp?set_by_headers=true&dont_set=1");
+ assertCookieValueMatch("JSESSIONID", "(.)*worker2");
}
@@ -117,11 +117,10 @@
*/
@Test
public void testCookieSetInHeaders() {
- beginAt("/cookies.jsp?threesamecookies=true&dont_set=1");
+ beginAt("/cookies.jsp?set_by_headers=true&dont_set=1");
List<HttpHeader> headers = getResponseHeaders();
boolean foundCookie1 = false;
boolean foundCookie2 = false;
- boolean foundCookie3 = false;
for (HttpHeader h : headers) {
if (h.getName().equals("Set-Cookie")) {
if (h.getValue().contains(".worker1")) {
@@ -130,11 +129,8 @@
else if (h.getValue().contains(".worker2")) {
foundCookie2 = true;
}
- else if (h.getValue().contains(".worker3")) {
- foundCookie3 = true;
- }
}
}
- assertTrue("getResponseHeaders should return all headers even duplicates", foundCookie1 && foundCookie2 && foundCookie3);
+ assertTrue("getResponseHeaders should return all headers even duplicates", foundCookie1 && foundCookie2);
}
}
\ No newline at end of file
Modified: trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/CookiesServlet.java
===================================================================
--- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/CookiesServlet.java 2011-03-14 11:11:36 UTC (rev 897)
+++ trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/CookiesServlet.java 2011-03-16 09:23:19 UTC (rev 898)
@@ -28,6 +28,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jetty.http.HttpHeaders;
+
public class CookiesServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -74,7 +76,7 @@
}
/*
- * To test if serveral same cookies with same path, domain and name
+ * To test if several same cookies with same path, domain and name
* are passed through to the test API. This "should" not be done by a
* server but there are use cases where it has to be done. One example is
* the JSESSIONID cookie which is set by Tomcat but has to be modified in a
@@ -85,7 +87,7 @@
*
* See http://tools.ietf.org/html/draft-ietf-httpstate-cookie-21#section-5.3, 11
*/
- if(request.getParameter("threesamecookies") != null) {
+ if(request.getParameter("set_by_headers") != null) {
// 1
Cookie jsessionIDCookie = new Cookie("JSESSIONID", "07D486AC962DE67F176F70B7C9816AAE.worker1");
jsessionIDCookie.setPath("/");
@@ -93,18 +95,13 @@
jsessionIDCookie.setMaxAge(-2);
jsessionIDCookie.setDomain("localhost");
response.addCookie(jsessionIDCookie);
- // 2
- jsessionIDCookie = new Cookie("JSESSIONID", "07D486AC962DE67F176F70B7C9816AAE.worker2");
- jsessionIDCookie.setMaxAge(-2);
- jsessionIDCookie.setDomain("localhost");
- response.addCookie(jsessionIDCookie);
- // 3
- jsessionIDCookie = new Cookie("JSESSIONID", "07D486AC962DE67F176F70B7C9816AAE.worker3");
- jsessionIDCookie.setMaxAge(-2);
- jsessionIDCookie.setDomain("localhost");
- jsessionIDCookie.setSecure(true);
- response.addCookie(jsessionIDCookie);
+ //With Jetty 6 we are now forced to access low level API to be able to set 2 same named cookies in the same response
+ org.eclipse.jetty.server.Response responseJetty = (org.eclipse.jetty.server.Response) response;
+ String cookie1 = responseJetty.getHttpFields().getStringField(HttpHeaders.SET_COOKIE);
+ // 2
+ String cookie2 = cookie1.replace("worker1", "worker2");
+ response.addHeader(HttpHeaders.SET_COOKIE, cookie2);
}
}
Modified: trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/JettySetup.java
===================================================================
--- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/JettySetup.java 2011-03-14 11:11:36 UTC (rev 897)
+++ trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/JettySetup.java 2011-03-16 09:23:19 UTC (rev 898)
@@ -19,25 +19,22 @@
package net.sourceforge.jwebunit.tests.util;
-import static org.junit.Assert.fail;
-
import java.net.URL;
-
import net.sourceforge.jwebunit.tests.JWebUnitAPITestCase;
-
+import org.eclipse.jetty.http.MimeTypes;
+import org.eclipse.jetty.security.HashLoginService;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.mortbay.jetty.Connector;
-import org.mortbay.jetty.Handler;
-import org.mortbay.jetty.MimeTypes;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.handler.DefaultHandler;
-import org.mortbay.jetty.handler.HandlerCollection;
-import org.mortbay.jetty.nio.SelectChannelConnector;
-import org.mortbay.jetty.security.HashUserRealm;
-import org.mortbay.jetty.security.UserRealm;
-import org.mortbay.jetty.webapp.WebAppContext;
+import static org.junit.Assert.fail;
+
/**
* Sets up and tears down the Jetty servlet engine before and after the tests in
* the <code>TestSuite</code> have run.
@@ -81,12 +78,10 @@
handlers.setHandlers(new Handler[]{wah, new DefaultHandler()});
jettyServer.setHandler(wah);
- HashUserRealm myrealm = new HashUserRealm("MyRealm");
- myrealm.put("jetty", "jetty");
- myrealm.addUserToRole("jetty", "user");
- myrealm.put("admin", "admin");
- myrealm.addUserToRole("admin", "admin");
- jettyServer.setUserRealms(new UserRealm[]{myrealm});
+ HashLoginService myrealm = new HashLoginService("MyRealm");
+ URL config = JettySetup.class.getResource("/jetty-users.properties");
+ myrealm.setConfig(config.toString());
+ jettyServer.addBean(myrealm);
wah.setContextPath(JWebUnitAPITestCase.JETTY_URL);
Added: trunk/jwebunit-commons-tests/src/main/resources/jetty-users.properties
===================================================================
--- trunk/jwebunit-commons-tests/src/main/resources/jetty-users.properties (rev 0)
+++ trunk/jwebunit-commons-tests/src/main/resources/jetty-users.properties 2011-03-16 09:23:19 UTC (rev 898)
@@ -0,0 +1,21 @@
+#
+# Copyright (c) 2010, JWebUnit team.
+#
+# This file is part of JWebUnit.
+#
+# JWebUnit is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# JWebUnit 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 Lesser General Public License
+# along with JWebUnit. If not, see <http://www.gnu.org/licenses/>.
+#
+
+jetty: jetty,user
+admin: admin,admin
Property changes on: trunk/jwebunit-commons-tests/src/main/resources/jetty-users.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/jwebunit-commons-tests/src/main/resources/logback-test.xml
===================================================================
--- trunk/jwebunit-commons-tests/src/main/resources/logback-test.xml 2011-03-14 11:11:36 UTC (rev 897)
+++ trunk/jwebunit-commons-tests/src/main/resources/logback-test.xml 2011-03-16 09:23:19 UTC (rev 898)
@@ -38,7 +38,7 @@
<logger name="org.apache.commons.httpclient" level="ERROR"/>
<logger name="org.apache.http" level="ERROR"/>
- <logger name="org.mortbay" level="ERROR"/>
+ <logger name="org.eclipse.jetty" level="ERROR"/>
<logger name="ch.qos.logback" level="ERROR"/>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-03-14 11:11:36 UTC (rev 897)
+++ trunk/pom.xml 2011-03-16 09:23:19 UTC (rev 898)
@@ -226,12 +226,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.7.2</version>
+ <version>2.8</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
- <version>2.4.3</version>
+ <version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -348,7 +348,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
- <version>2.3</version>
+ <version>2.4</version>
<inherited>false</inherited>
<executions>
<execution>
@@ -382,9 +382,9 @@
<version>1.3.RC2</version>
</dependency>
<dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
- <version>6.1.26</version>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>7.3.1.v20110307</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
@@ -541,7 +541,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.7.2</version>
+ <version>2.8</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
@@ -554,7 +554,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
- <version>2.3</version>
+ <version>2.4</version>
<inherited>false</inherited>
<reportSets>
<reportSet>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2011-03-14 11:11:42
|
Revision: 897
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=897&view=rev
Author: henryju
Date: 2011-03-14 11:11:36 +0000 (Mon, 14 Mar 2011)
Log Message:
-----------
Minor fixes and added hamcrest-library to pom.
Modified Paths:
--------------
trunk/jwebunit-commons-tests/pom.xml
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IElement.java
trunk/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java
trunk/pom.xml
Modified: trunk/jwebunit-commons-tests/pom.xml
===================================================================
--- trunk/jwebunit-commons-tests/pom.xml 2011-03-14 10:52:09 UTC (rev 896)
+++ trunk/jwebunit-commons-tests/pom.xml 2011-03-14 11:11:36 UTC (rev 897)
@@ -15,6 +15,10 @@
<artifactId>junit-dep</artifactId>
</dependency>
<dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</dependency>
Modified: trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IElement.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IElement.java 2011-03-14 10:52:09 UTC (rev 896)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/IElement.java 2011-03-14 11:11:36 UTC (rev 897)
@@ -17,9 +17,6 @@
* along with JWebUnit. If not, see <http://www.gnu.org/licenses/>.
*/
-/**
- *
- */
package net.sourceforge.jwebunit.api;
import java.util.List;
Modified: trunk/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java
===================================================================
--- trunk/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java 2011-03-14 10:52:09 UTC (rev 896)
+++ trunk/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java 2011-03-14 11:11:36 UTC (rev 897)
@@ -20,10 +20,6 @@
package net.sourceforge.jwebunit.htmlunit;
-import static org.junit.Assert.fail;
-
-import java.net.URL;
-
import net.sourceforge.jwebunit.tests.ButtonAssertionsTest;
import net.sourceforge.jwebunit.tests.CharsetTest;
import net.sourceforge.jwebunit.tests.CustomTesterTest;
@@ -37,7 +33,6 @@
import net.sourceforge.jwebunit.tests.IElementTest;
import net.sourceforge.jwebunit.tests.ImageTest;
import net.sourceforge.jwebunit.tests.JUnitPerfTest;
-import net.sourceforge.jwebunit.tests.JWebUnitAPITestCase;
import net.sourceforge.jwebunit.tests.JavaScriptEventsTest;
import net.sourceforge.jwebunit.tests.JavaScriptTest;
import net.sourceforge.jwebunit.tests.NavigationTest;
@@ -52,21 +47,8 @@
import net.sourceforge.jwebunit.tests.WebCookieTest;
import net.sourceforge.jwebunit.tests.XPathTest;
import net.sourceforge.jwebunit.tests.util.JettySetup;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
-import org.mortbay.jetty.Connector;
-import org.mortbay.jetty.Handler;
-import org.mortbay.jetty.MimeTypes;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.handler.DefaultHandler;
-import org.mortbay.jetty.handler.HandlerCollection;
-import org.mortbay.jetty.nio.SelectChannelConnector;
-import org.mortbay.jetty.security.HashUserRealm;
-import org.mortbay.jetty.security.UserRealm;
-import org.mortbay.jetty.webapp.WebAppContext;
/**
* Test Suite for JWebUnit.
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-03-14 10:52:09 UTC (rev 896)
+++ trunk/pom.xml 2011-03-14 11:11:36 UTC (rev 897)
@@ -377,6 +377,11 @@
<version>4.8.2</version>
</dependency>
<dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>1.3.RC2</version>
+ </dependency>
+ <dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.26</version>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2011-03-14 10:52:16
|
Revision: 896
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=896&view=rev
Author: henryju
Date: 2011-03-14 10:52:09 +0000 (Mon, 14 Mar 2011)
Log Message:
-----------
Improved JavaCC parsers to handle annotations (useful for @Deprecated).
Modified Paths:
--------------
trunk/jwebunit-code-generator/src/main/javacc/JWebUnit.jj
trunk/jwebunit-code-generator/src/main/javacc/WebTestCase.jj
Modified: trunk/jwebunit-code-generator/src/main/javacc/JWebUnit.jj
===================================================================
--- trunk/jwebunit-code-generator/src/main/javacc/JWebUnit.jj 2011-03-14 09:22:38 UTC (rev 895)
+++ trunk/jwebunit-code-generator/src/main/javacc/JWebUnit.jj 2011-03-14 10:52:09 UTC (rev 896)
@@ -533,9 +533,10 @@
* better error messages.
*/
-int Modifiers():
+Object[] Modifiers():
{
int modifiers = 0;
+ String annotations = "";
}
{
(
@@ -563,12 +564,12 @@
|
"strictfp" { modifiers |= ModifierSet.STRICTFP; }
|
- Annotation()
+ annotations = Annotation()
)
)*
{
- return modifiers;
+ return new Object[] {modifiers, annotations};
}
}
@@ -577,12 +578,14 @@
*/
void TypeDeclaration(StringBuffer sb):
{
+ Object[] modifiersAndAnnot;
int modifiers;
}
{
";"
|
- modifiers = Modifiers()
+ modifiersAndAnnot=Modifiers()
+ {modifiers = (Integer) modifiersAndAnnot[0];}
(
ClassOrInterfaceDeclaration(modifiers, sb)
|
@@ -713,8 +716,10 @@
void ClassOrInterfaceBodyDeclaration(boolean isInterface, StringBuffer sb):
{
boolean isNestedInterface = false;
+ Object[] modifiersAndAnnot;
int modifiers;
String comment;
+ String annotations;
}
{
LOOKAHEAD(2)
@@ -725,8 +730,12 @@
}
|
{comment=getToken(1).specialToken!=null?getToken(1).specialToken.image:"";}
- modifiers = Modifiers() // Just get all the modifiers out of the way. If you want to do
+ modifiersAndAnnot = Modifiers() // Just get all the modifiers out of the way. If you want to do
// more checks, pass the modifiers down to the member
+ {
+ modifiers = (Integer) modifiersAndAnnot[0];
+ annotations = (String) modifiersAndAnnot[1];
+ }
(
ClassOrInterfaceDeclaration(modifiers, sb)
|
@@ -738,7 +747,7 @@
LOOKAHEAD( Type() <IDENTIFIER> ( "[" "]" )* ( "," | "=" | ";" ) )
FieldDeclaration(modifiers)
|
- MethodDeclaration(modifiers, sb, comment)
+ MethodDeclaration(modifiers, sb, comment, annotations)
)
|
";"
@@ -779,7 +788,7 @@
"{" [ VariableInitializer() ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}"
}
-void MethodDeclaration(int modifiers, StringBuffer sb, String comment):
+void MethodDeclaration(int modifiers, StringBuffer sb, String comment, String annotations):
{ boolean append;
String resultType;
List params;
@@ -789,6 +798,7 @@
// Modifiers already matched in the caller!
{ append = (modifiers & ModifierSet.PUBLIC) != 0;}
{ if (append && comment!=null) sb.append(" ").append(comment).append("\n");}
+ { if (append && annotations!=null && !"".equals(annotations)) sb.append(" ").append(annotations).append("\n");}
{ if (append) sb.append(" public static ");}
[ TypeParameters() ]
isVoid=ResultType(append, sb)
@@ -1504,63 +1514,93 @@
/* Annotation syntax follows. */
-void Annotation():
-{}
+String Annotation():
{
+ StringBuffer sb = new StringBuffer();
+}
+{
LOOKAHEAD( "@" Name() "(" ( <IDENTIFIER> "=" | ")" ))
- NormalAnnotation()
+ NormalAnnotation(sb)
|
LOOKAHEAD( "@" Name() "(" )
- SingleMemberAnnotation()
+ SingleMemberAnnotation(sb)
|
- MarkerAnnotation()
+ MarkerAnnotation(sb)
+ {return sb.toString();}
}
-void NormalAnnotation():
-{}
+
+void NormalAnnotation(StringBuffer sb):
{
- "@" Name() "(" [ MemberValuePairs() ] ")"
+ String name;
+ String member = "";
}
+{
+ "@" name=Name() "(" [ member=MemberValuePairs() ] ")"
+ {sb.append("@").append(name).append("(").append(member).append(")");}
+}
-void MarkerAnnotation():
-{}
+void MarkerAnnotation(StringBuffer sb):
{
- "@" Name()
+ String name;
}
+{
+ "@" name=Name()
+ {sb.append("@").append(name);}
+}
-void SingleMemberAnnotation():
-{}
+void SingleMemberAnnotation(StringBuffer sb):
{
- "@" Name() "(" MemberValue() ")"
+ String name;
+ String member = "";
}
+{
+ "@" name=Name() "(" member=MemberValue() ")"
+ {sb.append("@").append(name).append("(").append(member).append(")");}
+}
-void MemberValuePairs():
-{}
+String MemberValuePairs():
{
- MemberValuePair() ( "," MemberValuePair() )*
+ StringBuffer sb = new StringBuffer();
+ String member;
}
+{
+ member=MemberValuePair() {sb.append(member);} ( "," member=MemberValuePair() {sb.append(", ").append(member);} )*
+ {return sb.toString();}
+}
-void MemberValuePair():
-{}
+String MemberValuePair():
{
- <IDENTIFIER> "=" MemberValue()
+ Token t;
+ String member;
}
+{
+ t=<IDENTIFIER> "=" member=MemberValue()
+ {return t.image + "=" + member;}
+}
-void MemberValue():
-{}
+String MemberValue():
{
- Annotation()
+ String result= "";
+}
+{
+ result=Annotation()
|
- MemberValueArrayInitializer()
+ result=MemberValueArrayInitializer()
|
ConditionalExpression()
+ {return result;}
}
-void MemberValueArrayInitializer():
-{}
+String MemberValueArrayInitializer():
{
- "{" MemberValue() ( LOOKAHEAD(2) "," MemberValue() )* [ "," ] "}"
+ StringBuffer sb = new StringBuffer();
+ String member;
}
+{
+ "{" member=MemberValue() {sb.append("{").append(member);} ( LOOKAHEAD(2) "," member=MemberValue() {sb.append(",").append(member);} )* [ "," ] "}" {sb.append("}");}
+ {return sb.toString();}
+}
/* Annotation Types. */
@@ -1579,10 +1619,12 @@
void AnnotationTypeMemberDeclaration():
{
+ Object[] modifiersAndAnnot;
int modifiers;
}
{
- modifiers = Modifiers()
+ modifiersAndAnnot = Modifiers()
+ {modifiers = (Integer) modifiersAndAnnot[0];}
(
LOOKAHEAD(Type() <IDENTIFIER> "(")
Type() <IDENTIFIER> "(" ")" [ DefaultValue() ] ";"
Modified: trunk/jwebunit-code-generator/src/main/javacc/WebTestCase.jj
===================================================================
--- trunk/jwebunit-code-generator/src/main/javacc/WebTestCase.jj 2011-03-14 09:22:38 UTC (rev 895)
+++ trunk/jwebunit-code-generator/src/main/javacc/WebTestCase.jj 2011-03-14 10:52:09 UTC (rev 896)
@@ -535,9 +535,10 @@
* better error messages.
*/
-int Modifiers():
+Object[] Modifiers():
{
int modifiers = 0;
+ String annotations = "";
}
{
(
@@ -565,12 +566,12 @@
|
"strictfp" { modifiers |= ModifierSet.STRICTFP; }
|
- Annotation()
+ annotations = Annotation()
)
)*
{
- return modifiers;
+ return new Object[] {modifiers, annotations};
}
}
@@ -579,12 +580,14 @@
*/
void TypeDeclaration(StringBuffer sb):
{
+ Object[] modifiersAndAnnot;
int modifiers;
}
{
";"
|
- modifiers = Modifiers()
+ modifiersAndAnnot=Modifiers()
+ {modifiers = (Integer) modifiersAndAnnot[0];}
(
ClassOrInterfaceDeclaration(modifiers, sb)
|
@@ -735,8 +738,10 @@
void ClassOrInterfaceBodyDeclaration(boolean isInterface, StringBuffer sb):
{
boolean isNestedInterface = false;
+ Object[] modifiersAndAnnot;
int modifiers;
String comment;
+ String annotations;
}
{
LOOKAHEAD(2)
@@ -747,8 +752,12 @@
}
|
{comment=getToken(1).specialToken!=null?getToken(1).specialToken.image:"";}
- modifiers = Modifiers() // Just get all the modifiers out of the way. If you want to do
+ modifiersAndAnnot = Modifiers() // Just get all the modifiers out of the way. If you want to do
// more checks, pass the modifiers down to the member
+ {
+ modifiers = (Integer) modifiersAndAnnot[0];
+ annotations = (String) modifiersAndAnnot[1];
+ }
(
ClassOrInterfaceDeclaration(modifiers, sb)
|
@@ -760,7 +769,7 @@
LOOKAHEAD( Type() <IDENTIFIER> ( "[" "]" )* ( "," | "=" | ";" ) )
FieldDeclaration(modifiers)
|
- MethodDeclaration(modifiers, sb, comment)
+ MethodDeclaration(modifiers, sb, comment, annotations)
)
|
";"
@@ -801,7 +810,7 @@
"{" [ VariableInitializer() ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}"
}
-void MethodDeclaration(int modifiers, StringBuffer sb, String comment):
+void MethodDeclaration(int modifiers, StringBuffer sb, String comment, String annotations):
{ boolean append;
String resultType;
List params;
@@ -811,6 +820,7 @@
// Modifiers already matched in the caller!
{ append = (modifiers & ModifierSet.PUBLIC) != 0;}
{ if (append && comment!=null) sb.append(" ").append(comment).append("\n");}
+ { if (append && annotations!=null && !"".equals(annotations)) sb.append(" ").append(annotations).append("\n");}
{ if (append) sb.append(" public ");}
[ TypeParameters() ]
isVoid=ResultType(append, sb)
@@ -1532,63 +1542,93 @@
/* Annotation syntax follows. */
-void Annotation():
-{}
+String Annotation():
{
+ StringBuffer sb = new StringBuffer();
+}
+{
LOOKAHEAD( "@" Name() "(" ( <IDENTIFIER> "=" | ")" ))
- NormalAnnotation()
+ NormalAnnotation(sb)
|
LOOKAHEAD( "@" Name() "(" )
- SingleMemberAnnotation()
+ SingleMemberAnnotation(sb)
|
- MarkerAnnotation()
+ MarkerAnnotation(sb)
+ {return sb.toString();}
}
-void NormalAnnotation():
-{}
+
+void NormalAnnotation(StringBuffer sb):
{
- "@" Name() "(" [ MemberValuePairs() ] ")"
+ String name;
+ String member = "";
}
+{
+ "@" name=Name() "(" [ member=MemberValuePairs() ] ")"
+ {sb.append("@").append(name).append("(").append(member).append(")");}
+}
-void MarkerAnnotation():
-{}
+void MarkerAnnotation(StringBuffer sb):
{
- "@" Name()
+ String name;
}
+{
+ "@" name=Name()
+ {sb.append("@").append(name);}
+}
-void SingleMemberAnnotation():
-{}
+void SingleMemberAnnotation(StringBuffer sb):
{
- "@" Name() "(" MemberValue() ")"
+ String name;
+ String member = "";
}
+{
+ "@" name=Name() "(" member=MemberValue() ")"
+ {sb.append("@").append(name).append("(").append(member).append(")");}
+}
-void MemberValuePairs():
-{}
+String MemberValuePairs():
{
- MemberValuePair() ( "," MemberValuePair() )*
+ StringBuffer sb = new StringBuffer();
+ String member;
}
+{
+ member=MemberValuePair() {sb.append(member);} ( "," member=MemberValuePair() {sb.append(", ").append(member);} )*
+ {return sb.toString();}
+}
-void MemberValuePair():
-{}
+String MemberValuePair():
{
- <IDENTIFIER> "=" MemberValue()
+ Token t;
+ String member;
}
+{
+ t=<IDENTIFIER> "=" member=MemberValue()
+ {return t.image + "=" + member;}
+}
-void MemberValue():
-{}
+String MemberValue():
{
- Annotation()
+ String result= "";
+}
+{
+ result=Annotation()
|
- MemberValueArrayInitializer()
+ result=MemberValueArrayInitializer()
|
ConditionalExpression()
+ {return result;}
}
-void MemberValueArrayInitializer():
-{}
+String MemberValueArrayInitializer():
{
- "{" MemberValue() ( LOOKAHEAD(2) "," MemberValue() )* [ "," ] "}"
+ StringBuffer sb = new StringBuffer();
+ String member;
}
+{
+ "{" member=MemberValue() {sb.append("{").append(member);} ( LOOKAHEAD(2) "," member=MemberValue() {sb.append(",").append(member);} )* [ "," ] "}" {sb.append("}");}
+ {return sb.toString();}
+}
/* Annotation Types. */
@@ -1607,10 +1647,12 @@
void AnnotationTypeMemberDeclaration():
{
+ Object[] modifiersAndAnnot;
int modifiers;
}
{
- modifiers = Modifiers()
+ modifiersAndAnnot = Modifiers()
+ {modifiers = (Integer) modifiersAndAnnot[0];}
(
LOOKAHEAD(Type() <IDENTIFIER> "(")
Type() <IDENTIFIER> "(" ")" [ DefaultValue() ] ";"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SourceForge.net <no...@so...> - 2011-03-14 09:34:42
|
Bugs item #3190055, was opened at 2011-02-23 12:34 Message generated for change (Comment added) made by henryju You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. >Category: Core API >Group: Release 3.0 >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Achim Westermann (achimwestermann) >Assigned to: Julien HENRY (henryju) Summary: Handling same named Headers with HtmlUnit Initial Comment: Intro: Great work thanks! Scenario: Server sends two same named cookies (e.g. servlet container adds JSESSIONID and Servlet filter has to correct that cookie, but cannot kill the first cookie from the response). The 2nd header cookie sets a special attribute, e.g. "HttpOnly" which the first one does not have. Problem: assertCookieValueMatch("JSESSIONID", "(.)*HttpOnly"); will take the first cookie with that name and fail. This is because HtmlUnitTestingEngineImpl in public String getHeader(String name) trusts on com.gargoylesoftware.htmlunit.Webresponse#getResponseHeaderValue(String name) which will return the first header. Also the workaround "getAllHeaders()" is a bit unclean. In HtmlUnitTestingEngineImpl#getAllHeaders() all values are put into a map by header name. The latter same named header fields will overwrite the earlier ones. Expected behaviour: For HtmlUnitTestingEngineImple#getHeader(String name) the last same named header should be returned. Take e.g. this specification (regarding Cookie setting) : http://tools.ietf.org/html/draft-ietf-httpstate-cookie-21#section-4.1.2 -> The last cookie wins. For HtmlUnitTestingEngineImpl#getAllHeaders() some data structure (multi - map?) should be returned that preserves all headers in that order. Thanks a lot for your great work! Achim P.S.: If you'd like a patch, just contact me. - HtmlUnitTestingEngineImpl ---------------------------------------------------------------------- >Comment By: Julien HENRY (henryju) Date: 2011-03-14 10:34 Message: Hi Achim, Thanks for the patch and test case. I applied it with several modifications. I tried to keep binary compatibility so I keep existing getAllHeaders method but deprecated it. I have added a new method: getResponseHeaders that returns all headers (even duplicate). Feel free to comment here if I miss anything. Regards, Julien ---------------------------------------------------------------------- Comment By: Achim Westermann (achimwestermann) Date: 2011-03-11 14:47 Message: Hi Julian, it took me some time to set up eclipse with m2eclipse (dependency hell), but now I had the time to write a test and propose a bugfix. Caution there is an API change! I attach two patches. One for the new test to see what is not working as I expect it. And one proposed bugfix. I worked on assertCookieValueMatch to use the last cookie with the given name being checked. Forget about my statement about com.gargoylesoftware.htmlunit.Webresponse#getResponseHeaderValue(String name) in this matter. I found out that assertCookieValueMatch works on getTestingEngine().getCookies() which returns everything right! I worked on ITestingEngine.getAllHeaders() and the HTMLunit impl to avoid loosing same named cookies. I did that by changing the data structure returned to allow passing multiple same named cookies. I did this in favour of a commons collections MultiValueMap as the latter would have disallowed to use generic code (and forced us to use casts) . If the patch is not working I could attach the plain files. Eclipse -> checkout maven project via scm did have it's on idea on which projects to create in my workspace (even if everything works well). kind regards, Achim ---------------------------------------------------------------------- Comment By: Julien HENRY (henryju) Date: 2011-02-23 13:38 Message: Hi Achim, Thanks for your detailed report. Could you please provide a patch with the fix and possibly a JUnit test that verify this situation. Thanks Julien ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 |
|
From: <he...@us...> - 2011-03-14 09:22:45
|
Revision: 895
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=895&view=rev
Author: henryju
Date: 2011-03-14 09:22:38 +0000 (Mon, 14 Mar 2011)
Log Message:
-----------
[3190055] Fixed support of same named cookies/headers.
Modified Paths:
--------------
trunk/jwebunit-code-generator/src/main/javacc/JWebUnit.jj
trunk/jwebunit-code-generator/src/main/javacc/WebTestCase.jj
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebCookieTest.java
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/CookiesServlet.java
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
trunk/src/changes/changes.xml
Added Paths:
-----------
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/HttpHeader.java
Modified: trunk/jwebunit-code-generator/src/main/javacc/JWebUnit.jj
===================================================================
--- trunk/jwebunit-code-generator/src/main/javacc/JWebUnit.jj 2011-01-27 13:42:12 UTC (rev 894)
+++ trunk/jwebunit-code-generator/src/main/javacc/JWebUnit.jj 2011-03-14 09:22:38 UTC (rev 895)
@@ -493,6 +493,7 @@
sb.append("import java.util.List;\n");
sb.append("import java.util.Map;\n");
sb.append("import java.net.URL;\n\n");
+ sb.append("import net.sourceforge.jwebunit.api.HttpHeader;\n");
sb.append("import net.sourceforge.jwebunit.api.IElement;\n");
sb.append("import net.sourceforge.jwebunit.api.ITestingEngine;\n");
sb.append("import net.sourceforge.jwebunit.exception.TestingEngineResponseException;\n");
Modified: trunk/jwebunit-code-generator/src/main/javacc/WebTestCase.jj
===================================================================
--- trunk/jwebunit-code-generator/src/main/javacc/WebTestCase.jj 2011-01-27 13:42:12 UTC (rev 894)
+++ trunk/jwebunit-code-generator/src/main/javacc/WebTestCase.jj 2011-03-14 09:22:38 UTC (rev 895)
@@ -493,6 +493,7 @@
sb.append("import java.util.List;\n");
sb.append("import java.util.Map;\n");
sb.append("import java.net.URL;\n\n");
+ sb.append("import net.sourceforge.jwebunit.api.HttpHeader;\n");
sb.append("import net.sourceforge.jwebunit.api.IElement;\n");
sb.append("import net.sourceforge.jwebunit.api.ITestingEngine;\n");
sb.append("import net.sourceforge.jwebunit.exception.TestingEngineResponseException;\n");
Modified: trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebCookieTest.java
===================================================================
--- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebCookieTest.java 2011-01-27 13:42:12 UTC (rev 894)
+++ trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/WebCookieTest.java 2011-03-14 09:22:38 UTC (rev 895)
@@ -19,16 +19,21 @@
package net.sourceforge.jwebunit.tests;
+import java.util.List;
+import net.sourceforge.jwebunit.api.HttpHeader;
+import org.junit.Test;
+
import static net.sourceforge.jwebunit.junit.JWebUnit.assertCookiePresent;
import static net.sourceforge.jwebunit.junit.JWebUnit.assertCookieValueEquals;
import static net.sourceforge.jwebunit.junit.JWebUnit.assertCookieValueMatch;
import static net.sourceforge.jwebunit.junit.JWebUnit.assertTextPresent;
import static net.sourceforge.jwebunit.junit.JWebUnit.beginAt;
+import static net.sourceforge.jwebunit.junit.JWebUnit.getResponseHeaders;
import static net.sourceforge.jwebunit.junit.JWebUnit.getTestContext;
import static net.sourceforge.jwebunit.junit.JWebUnit.gotoPage;
import static net.sourceforge.jwebunit.junit.JWebUnit.setBaseUrl;
+import static org.junit.Assert.assertTrue;
-import org.junit.Test;
/**
* Test the Cookies methods provided by WebTestCase.
@@ -44,38 +49,56 @@
setBaseUrl(HOST_PATH);
}
- @Test public void testAddCookie() {
+ @Test
+ public void testAddCookie() {
beginAt("/cookies.jsp");
assertTextPresent("cookie1=Cookievalue1");
}
- @Test public void testAddAnotherCookie() {
+ @Test
+ public void testAddAnotherCookie() {
getTestContext().addCookie("cookie2", "Cookievalue2", "localhost");
beginAt("/cookies.jsp");
assertTextPresent("cookie1=Cookievalue1");
assertTextPresent("cookie2=Cookievalue2");
}
- @Test public void testAssertCookiePresent() throws Throwable {
+ @Test
+ public void testAssertCookiePresent() throws Throwable {
beginAt("/cookies.jsp");
assertCookiePresent("serveurCookie");
}
- @Test public void testAssertCookieValue() throws Throwable {
+ @Test
+ public void testAssertCookieValue() throws Throwable {
beginAt("/cookies.jsp");
assertCookieValueEquals("serveurCookie", "foo");
}
- @Test public void testAssertCookieMatch() throws Throwable {
+ @Test
+ public void testAssertCookieMatch() throws Throwable {
beginAt("/cookies.jsp");
assertCookieValueMatch("serveurCookie", "fo*");
}
/**
+ * When there are several cookies with the same name, it is the last one that should
+ * be taken.
+ * See <a href="http://tools.ietf.org/html/draft-ietf-httpstate-cookie-21#section-5.3">the spec</a> (§ 11)
+ */
+ @Test
+ public void testCookieMatchLastCookie() {
+ beginAt("/cookies.jsp?threesamecookies=true&dont_set=1");
+ assertCookieValueMatch("JSESSIONID", "(.)*worker3");
+ }
+
+
+ /**
* Test that the cookie still exists across multiple requests,
* even if the cookie is not explicitly set each time.
*/
- @Test public void testCookieWithoutExplicitSet() {
+ @Test
+ public void testCookieWithoutExplicitSet() {
beginAt("/cookies.jsp"); // beginAt also resets cookies
assertCookieValueEquals("serveurCookie", "foo");
gotoPage("/cookies.jsp?dont_set=1");
@@ -84,8 +107,34 @@
assertCookieValueEquals("serveurCookie", "foo"); // should still be there
gotoPage("/cookies.jsp?dont_set=1");
assertCookieValueEquals("serveurCookie", "foo"); // should still be there
-
-
}
+ /**
+ * Tests if all cookies are received when the server sets several cookies
+ * with same domain, path and name.<p>
+ *
+ * See http://tools.ietf.org/html/draft-ietf-httpstate-cookie-21#section-5.3, 11
+ */
+ @Test
+ public void testCookieSetInHeaders() {
+ beginAt("/cookies.jsp?threesamecookies=true&dont_set=1");
+ List<HttpHeader> headers = getResponseHeaders();
+ boolean foundCookie1 = false;
+ boolean foundCookie2 = false;
+ boolean foundCookie3 = false;
+ for (HttpHeader h : headers) {
+ if (h.getName().equals("Set-Cookie")) {
+ if (h.getValue().contains(".worker1")) {
+ foundCookie1 = true;
+ }
+ else if (h.getValue().contains(".worker2")) {
+ foundCookie2 = true;
+ }
+ else if (h.getValue().contains(".worker3")) {
+ foundCookie3 = true;
+ }
+ }
+ }
+ assertTrue("getResponseHeaders should return all headers even duplicates", foundCookie1 && foundCookie2 && foundCookie3);
+ }
}
\ No newline at end of file
Modified: trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/CookiesServlet.java
===================================================================
--- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/CookiesServlet.java 2011-01-27 13:42:12 UTC (rev 894)
+++ trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/CookiesServlet.java 2011-03-14 09:22:38 UTC (rev 895)
@@ -72,6 +72,40 @@
Cookie cookie = new Cookie("serveurCookie","foo");
response.addCookie(cookie);
}
+
+ /*
+ * To test if serveral same cookies with same path, domain and name
+ * are passed through to the test API. This "should" not be done by a
+ * server but there are use cases where it has to be done. One example is
+ * the JSESSIONID cookie which is set by Tomcat but has to be modified in a
+ * mod_jk - clustered environment in order to let the client jump to another
+ * worker (-> Tomcat cluster member). However within the web application the
+ * JSESSIONID cookie has already been added to the response and cannot be
+ * removed from there via API. Solution is to set another cookie to overwrite this.
+ *
+ * See http://tools.ietf.org/html/draft-ietf-httpstate-cookie-21#section-5.3, 11
+ */
+ if(request.getParameter("threesamecookies") != null) {
+ // 1
+ Cookie jsessionIDCookie = new Cookie("JSESSIONID", "07D486AC962DE67F176F70B7C9816AAE.worker1");
+ jsessionIDCookie.setPath("/");
+ // session cookie:
+ jsessionIDCookie.setMaxAge(-2);
+ jsessionIDCookie.setDomain("localhost");
+ response.addCookie(jsessionIDCookie);
+ // 2
+ jsessionIDCookie = new Cookie("JSESSIONID", "07D486AC962DE67F176F70B7C9816AAE.worker2");
+ jsessionIDCookie.setMaxAge(-2);
+ jsessionIDCookie.setDomain("localhost");
+ response.addCookie(jsessionIDCookie);
+
+ // 3
+ jsessionIDCookie = new Cookie("JSESSIONID", "07D486AC962DE67F176F70B7C9816AAE.worker3");
+ jsessionIDCookie.setMaxAge(-2);
+ jsessionIDCookie.setDomain("localhost");
+ jsessionIDCookie.setSecure(true);
+ response.addCookie(jsessionIDCookie);
+ }
}
}
Added: trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/HttpHeader.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/HttpHeader.java (rev 0)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/HttpHeader.java 2011-03-14 09:22:38 UTC (rev 895)
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2010, JWebUnit team.
+ *
+ * This file is part of JWebUnit.
+ *
+ * JWebUnit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JWebUnit 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 Lesser General Public License
+ * along with JWebUnit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.sourceforge.jwebunit.api;
+
+/**
+ * A name/value pair to store HTTP headers.
+ *
+ * Inspired from HtmlUnit NameValuePair.
+ * @author Julien HENRY
+ */
+public class HttpHeader {
+
+ /** The name. */
+ private final String name_;
+
+ /** The value. */
+ private final String value_;
+
+ /**
+ * Creates a new instance.
+ * @param name the name
+ * @param value the value
+ */
+ public HttpHeader(final String name, final String value) {
+ name_ = name;
+ value_ = value;
+ }
+
+ /**
+ * Returns the name.
+ * @return the name
+ */
+ public String getName() {
+ return name_;
+ }
+
+ /**
+ * Returns the value.
+ * @return the value
+ */
+ public String getValue() {
+ return value_;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return name_ + "=" + value_;
+ }
+
+}
Property changes on: trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/HttpHeader.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java 2011-01-27 13:42:12 UTC (rev 894)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/api/ITestingEngine.java 2011-03-14 09:22:38 UTC (rev 895)
@@ -19,6 +19,8 @@
package net.sourceforge.jwebunit.api;
+import java.util.Map;
+
import java.io.InputStream;
import java.net.URL;
import java.util.List;
@@ -907,22 +909,30 @@
*/
String getHeader(String name);
- /**
- * Get all headers.
- *
- * @return The header values stored in a map.
- */
- java.util.Map<String,String> getAllHeaders();
-
- /**
- * Should the tester ignore failing status codes (300+)? Otherwise,
- * failing status codes will throw an exception.
- *
- * @param ignore
- */
- public void setIgnoreFailingStatusCodes(boolean ignore);
-
/**
+ * Get all distinct response headers. In case there are duplicate headers with same name, the last one will be returned.
+ *
+ * @return The header values stored in a map.
+ * @deprecated Use {@link #getResponseHeaders()}
+ */
+ @Deprecated
+ Map<String, String> getAllHeaders();
+
+ /**
+ * Get all response headers.
+ * @return the response headers as a list of {@link HttpHeader}s
+ */
+ List<HttpHeader> getResponseHeaders();
+
+ /**
+ * Should the tester ignore failing status codes (300+)? Otherwise,
+ * failing status codes will throw an exception.
+ *
+ * @param ignore
+ */
+ public void setIgnoreFailingStatusCodes(boolean ignore);
+
+ /**
* Get all the comments in a document, as a list of strings.
*/
public List<String> getComments();
Modified: trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 2011-01-27 13:42:12 UTC (rev 894)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 2011-03-14 09:22:38 UTC (rev 895)
@@ -37,10 +37,9 @@
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
-
import javax.imageio.ImageIO;
import javax.servlet.http.Cookie;
-
+import net.sourceforge.jwebunit.api.HttpHeader;
import net.sourceforge.jwebunit.api.IElement;
import net.sourceforge.jwebunit.api.ITestingEngine;
import net.sourceforge.jwebunit.exception.ExpectedJavascriptAlertException;
@@ -54,7 +53,6 @@
import net.sourceforge.jwebunit.javascript.JavascriptPrompt;
import net.sourceforge.jwebunit.util.TestContext;
import net.sourceforge.jwebunit.util.TestingEngineRegistry;
-
import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;
@@ -399,10 +397,21 @@
* Get all response headers.
*
* @return A map of response headers
+ * @deprecated This method do not deal with several headers with same name. Use {@link #getResponseHeaders()} instead.
*/
+ @Deprecated
public Map<String, String> getAllHeaders() {
- return getTestingEngine().getAllHeaders();
+ return getTestingEngine().getAllHeaders();
}
+
+ /**
+ * Return all HTTP headers that are in last response. It is possible to have several headers with same name.
+ *
+ * @return A list of {@link HttpHeader} elements.
+ */
+ public List<HttpHeader> getResponseHeaders() {
+ return getTestingEngine().getResponseHeaders();
+ }
/**
* Assert title of current html page in conversation matches an expected
@@ -2269,12 +2278,11 @@
List<?> cookies = getTestingEngine().getCookies();
for (Iterator<?> i = cookies.iterator(); i.hasNext();) {
Cookie c = (Cookie) i.next();
- if (c.getName().equals(cookieName)) {
- assertEquals(expectedValue, c.getValue());
+ if (c.getName().equals(cookieName) && c.getValue().equals(expectedValue)) {
return;
}
}
- fail("Should not be reached");
+ fail("Could not find cookie with name [" + cookieName + "] and value [" + expectedValue + "]");
}
/**
@@ -2289,19 +2297,17 @@
try {
re = new RE(regexp, RE.MATCH_SINGLELINE);
} catch (RESyntaxException e) {
- fail(e.toString());
+ fail(e.getMessage());
}
List<?> cookies = getTestingEngine().getCookies();
for (Iterator<?> i = cookies.iterator(); i.hasNext();) {
Cookie c = (Cookie) i.next();
- if (c.getName().equals(cookieName)) {
- assertTrue("Unable to match [" + regexp
- + "] in cookie \"" + cookieName + "\"", re.match(c
- .getValue()));
+ if (c.getName().equals(cookieName) &&
+ re.match(c.getValue())) {
return;
}
}
- fail("Should not be reached");
+ fail("Could not find cookie with name [" + cookieName + "] with value matching [" + regexp + "]");
}
// Form interaction methods
Modified: trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
===================================================================
--- trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-01-27 13:42:12 UTC (rev 894)
+++ trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-03-14 09:22:38 UTC (rev 895)
@@ -19,6 +19,8 @@
package net.sourceforge.jwebunit.htmlunit;
+import net.sourceforge.jwebunit.api.HttpHeader;
+
import org.apache.http.auth.AuthScope;
import java.io.IOException;
@@ -2331,6 +2333,7 @@
/* (non-Javadoc)
* @see net.sourceforge.jwebunit.api.ITestingEngine#getAllHeaders()
*/
+ @Deprecated
public Map<String, String> getAllHeaders() {
Map<String, String> map = new java.util.HashMap<String, String>();
for (NameValuePair header : getWebResponse().getResponseHeaders()) {
@@ -2338,6 +2341,14 @@
}
return map;
}
+
+ public List<HttpHeader> getResponseHeaders() {
+ List<HttpHeader> result = new LinkedList<HttpHeader>();
+ for (NameValuePair header : getWebResponse().getResponseHeaders()) {
+ result.add(new HttpHeader(header.getName(), header.getValue()));
+ }
+ return result;
+ }
/**
* An alternative to setting the {@link TestContext#setUserAgent(String) user agent string manually}
Modified: trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java
===================================================================
--- trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java 2011-01-27 13:42:12 UTC (rev 894)
+++ trunk/jwebunit-selenium-plugin/src/main/java/net/sourceforge/jwebunit/selenium/SeleniumTestingEngineImpl.java 2011-03-14 09:22:38 UTC (rev 895)
@@ -20,6 +20,8 @@
package net.sourceforge.jwebunit.selenium;
+import net.sourceforge.jwebunit.api.HttpHeader;
+
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
@@ -720,10 +722,16 @@
/* (non-Javadoc)
* @see net.sourceforge.jwebunit.api.ITestingEngine#getAllHeaders()
*/
+ @Deprecated
public Map<String, String> getAllHeaders() {
// TODO implement method
throw new UnsupportedOperationException("getAllHeaders");
}
+
+ public List<HttpHeader> getResponseHeaders() {
+ // TODO implement method
+ throw new UnsupportedOperationException("getResponseHeaders");
+ }
/* (non-Javadoc)
* @see net.sourceforge.jwebunit.api.ITestingEngine#getHeader(java.lang.String)
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2011-01-27 13:42:12 UTC (rev 894)
+++ trunk/src/changes/changes.xml 2011-03-14 09:22:38 UTC (rev 895)
@@ -32,6 +32,12 @@
</properties>
<body>
<release version="3.0" date="UNKNOW" description="Updated all internals to JUnit 4">
+ <action type="fix" dev="henryju" issue="3190055" due-to="Achim Westermann">
+ Fixed handling of several cookies/headers with same name. getAllHeaders() was wrongly returning only the latest header
+ header with the same name so this method was deprecated and a new one was added with a different return type.
+ See getResponseHeaders().
+ AssertCookiePresent/Match was also updated to take the last set cookie of the given name instead of the first one.
+ </action>
<action type="add" dev="henryju" issue="3166502" due-to="Harri">
Added indexed alternatives of methods clickLinkWithImage, assertLinkPresentWithImage and assertLinkNotPresentWithImage.
</action>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SourceForge.net <no...@so...> - 2011-03-11 13:47:24
|
Bugs item #3190055, was opened at 2011-02-23 12:34 Message generated for change (Comment added) made by achimwestermann You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Achim Westermann (achimwestermann) Assigned to: Nobody/Anonymous (nobody) Summary: Handling same named Headers with HtmlUnit Initial Comment: Intro: Great work thanks! Scenario: Server sends two same named cookies (e.g. servlet container adds JSESSIONID and Servlet filter has to correct that cookie, but cannot kill the first cookie from the response). The 2nd header cookie sets a special attribute, e.g. "HttpOnly" which the first one does not have. Problem: assertCookieValueMatch("JSESSIONID", "(.)*HttpOnly"); will take the first cookie with that name and fail. This is because HtmlUnitTestingEngineImpl in public String getHeader(String name) trusts on com.gargoylesoftware.htmlunit.Webresponse#getResponseHeaderValue(String name) which will return the first header. Also the workaround "getAllHeaders()" is a bit unclean. In HtmlUnitTestingEngineImpl#getAllHeaders() all values are put into a map by header name. The latter same named header fields will overwrite the earlier ones. Expected behaviour: For HtmlUnitTestingEngineImple#getHeader(String name) the last same named header should be returned. Take e.g. this specification (regarding Cookie setting) : http://tools.ietf.org/html/draft-ietf-httpstate-cookie-21#section-4.1.2 -> The last cookie wins. For HtmlUnitTestingEngineImpl#getAllHeaders() some data structure (multi - map?) should be returned that preserves all headers in that order. Thanks a lot for your great work! Achim P.S.: If you'd like a patch, just contact me. - HtmlUnitTestingEngineImpl ---------------------------------------------------------------------- >Comment By: Achim Westermann (achimwestermann) Date: 2011-03-11 14:47 Message: Hi Julian, it took me some time to set up eclipse with m2eclipse (dependency hell), but now I had the time to write a test and propose a bugfix. Caution there is an API change! I attach two patches. One for the new test to see what is not working as I expect it. And one proposed bugfix. I worked on assertCookieValueMatch to use the last cookie with the given name being checked. Forget about my statement about com.gargoylesoftware.htmlunit.Webresponse#getResponseHeaderValue(String name) in this matter. I found out that assertCookieValueMatch works on getTestingEngine().getCookies() which returns everything right! I worked on ITestingEngine.getAllHeaders() and the HTMLunit impl to avoid loosing same named cookies. I did that by changing the data structure returned to allow passing multiple same named cookies. I did this in favour of a commons collections MultiValueMap as the latter would have disallowed to use generic code (and forced us to use casts) . If the patch is not working I could attach the plain files. Eclipse -> checkout maven project via scm did have it's on idea on which projects to create in my workspace (even if everything works well). kind regards, Achim ---------------------------------------------------------------------- Comment By: Julien HENRY (henryju) Date: 2011-02-23 13:38 Message: Hi Achim, Thanks for your detailed report. Could you please provide a patch with the fix and possibly a JUnit test that verify this situation. Thanks Julien ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 |
|
From: SourceForge.net <no...@so...> - 2011-02-23 12:38:57
|
Bugs item #3190055, was opened at 2011-02-23 12:34 Message generated for change (Comment added) made by henryju You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Achim Westermann (achimwestermann) Assigned to: Nobody/Anonymous (nobody) Summary: Handling same named Headers with HtmlUnit Initial Comment: Intro: Great work thanks! Scenario: Server sends two same named cookies (e.g. servlet container adds JSESSIONID and Servlet filter has to correct that cookie, but cannot kill the first cookie from the response). The 2nd header cookie sets a special attribute, e.g. "HttpOnly" which the first one does not have. Problem: assertCookieValueMatch("JSESSIONID", "(.)*HttpOnly"); will take the first cookie with that name and fail. This is because HtmlUnitTestingEngineImpl in public String getHeader(String name) trusts on com.gargoylesoftware.htmlunit.Webresponse#getResponseHeaderValue(String name) which will return the first header. Also the workaround "getAllHeaders()" is a bit unclean. In HtmlUnitTestingEngineImpl#getAllHeaders() all values are put into a map by header name. The latter same named header fields will overwrite the earlier ones. Expected behaviour: For HtmlUnitTestingEngineImple#getHeader(String name) the last same named header should be returned. Take e.g. this specification (regarding Cookie setting) : http://tools.ietf.org/html/draft-ietf-httpstate-cookie-21#section-4.1.2 -> The last cookie wins. For HtmlUnitTestingEngineImpl#getAllHeaders() some data structure (multi - map?) should be returned that preserves all headers in that order. Thanks a lot for your great work! Achim P.S.: If you'd like a patch, just contact me. - HtmlUnitTestingEngineImpl ---------------------------------------------------------------------- >Comment By: Julien HENRY (henryju) Date: 2011-02-23 13:38 Message: Hi Achim, Thanks for your detailed report. Could you please provide a patch with the fix and possibly a JUnit test that verify this situation. Thanks Julien ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 |
|
From: SourceForge.net <no...@so...> - 2011-02-23 11:34:47
|
Bugs item #3190055, was opened at 2011-02-23 12:34 Message generated for change (Tracker Item Submitted) made by achimwestermann You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Achim Westermann (achimwestermann) Assigned to: Nobody/Anonymous (nobody) Summary: Handling same named Headers with HtmlUnit Initial Comment: Intro: Great work thanks! Scenario: Server sends two same named cookies (e.g. servlet container adds JSESSIONID and Servlet filter has to correct that cookie, but cannot kill the first cookie from the response). The 2nd header cookie sets a special attribute, e.g. "HttpOnly" which the first one does not have. Problem: assertCookieValueMatch("JSESSIONID", "(.)*HttpOnly"); will take the first cookie with that name and fail. This is because HtmlUnitTestingEngineImpl in public String getHeader(String name) trusts on com.gargoylesoftware.htmlunit.Webresponse#getResponseHeaderValue(String name) which will return the first header. Also the workaround "getAllHeaders()" is a bit unclean. In HtmlUnitTestingEngineImpl#getAllHeaders() all values are put into a map by header name. The latter same named header fields will overwrite the earlier ones. Expected behaviour: For HtmlUnitTestingEngineImple#getHeader(String name) the last same named header should be returned. Take e.g. this specification (regarding Cookie setting) : http://tools.ietf.org/html/draft-ietf-httpstate-cookie-21#section-4.1.2 -> The last cookie wins. For HtmlUnitTestingEngineImpl#getAllHeaders() some data structure (multi - map?) should be returned that preserves all headers in that order. Thanks a lot for your great work! Achim P.S.: If you'd like a patch, just contact me. - HtmlUnitTestingEngineImpl ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 |
|
From: SourceForge.net <no...@so...> - 2011-02-17 08:35:24
|
Feature Requests item #3184600, was opened at 2011-02-17 10:35 Message generated for change (Tracker Item Submitted) made by mdm42 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497985&aid=3184600&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Core API Group: None Status: Open Priority: 5 Private: No Submitted By: Mike Morris (mdm42) Assigned to: Nobody/Anonymous (nobody) Summary: assertCookieNotPresent() Initial Comment: Trivially easy nice to have: assertCookieNotPresent() ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497985&aid=3184600&group_id=61302 |
|
From: SourceForge.net <no...@so...> - 2011-01-31 14:09:05
|
Bugs item #3166974, was opened at 2011-01-28 12:31 Message generated for change (Comment added) made by n116373 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166974&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: HtmlUnit plugin Group: Release 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Harri (n116373) Assigned to: Nobody/Anonymous (nobody) Summary: HtmlUnitTestingEngineImpl.getSubmitButton() fails with Ajax Initial Comment: If page opens dialog form (e.g. confirm window) with Ajax, HtmlUnitTestingEngineImpl.getSubmitButton(buttonName) does not find the submit button. I don't exactly know what current form member field means here, but if I set it to null in debugger, the requested button is found after getCurrentPage.getForms(). So the method should first check, if button is found in current form, and then if it is found in other forms on the page. getTextFieldValue(paramName) works this way, for example. I guess the workaround would be using setWorkingForm(). ---------------------------------------------------------------------- >Comment By: Harri (n116373) Date: 2011-01-31 16:08 Message: Same applies to private methods getCheckBox(), possible some others too. Currently I am setting the current form field to null via reflection, as page contains so many different forms, that it is painful to maintain the index, and null can not be set directly or with non-existing index in setWorkingForm(). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166974&group_id=61302 |
|
From: SourceForge.net <no...@so...> - 2011-01-28 10:31:55
|
Bugs item #3166974, was opened at 2011-01-28 12:31 Message generated for change (Tracker Item Submitted) made by n116373 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166974&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: HtmlUnit plugin Group: Release 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Harri (n116373) Assigned to: Nobody/Anonymous (nobody) Summary: HtmlUnitTestingEngineImpl.getSubmitButton() fails with Ajax Initial Comment: If page opens dialog form (e.g. confirm window) with Ajax, HtmlUnitTestingEngineImpl.getSubmitButton(buttonName) does not find the submit button. I don't exactly know what current form member field means here, but if I set it to null in debugger, the requested button is found after getCurrentPage.getForms(). So the method should first check, if button is found in current form, and then if it is found in other forms on the page. getTextFieldValue(paramName) works this way, for example. I guess the workaround would be using setWorkingForm(). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166974&group_id=61302 |
|
From: <he...@us...> - 2011-01-27 13:42:19
|
Revision: 894
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=894&view=rev
Author: henryju
Date: 2011-01-27 13:42:12 +0000 (Thu, 27 Jan 2011)
Log Message:
-----------
Updated some dependencies and plugins versions.
Modified Paths:
--------------
trunk/jwebunit-core/pom.xml
trunk/jwebunit-htmlunit-plugin/pom.xml
trunk/pom.xml
Modified: trunk/jwebunit-core/pom.xml
===================================================================
--- trunk/jwebunit-core/pom.xml 2011-01-27 13:15:33 UTC (rev 893)
+++ trunk/jwebunit-core/pom.xml 2011-01-27 13:42:12 UTC (rev 894)
@@ -18,8 +18,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.7</version>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Modified: trunk/jwebunit-htmlunit-plugin/pom.xml
===================================================================
--- trunk/jwebunit-htmlunit-plugin/pom.xml 2011-01-27 13:15:33 UTC (rev 893)
+++ trunk/jwebunit-htmlunit-plugin/pom.xml 2011-01-27 13:42:12 UTC (rev 894)
@@ -17,8 +17,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.7</version>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-27 13:15:33 UTC (rev 893)
+++ trunk/pom.xml 2011-01-27 13:42:12 UTC (rev 894)
@@ -226,7 +226,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.7</version>
+ <version>2.7.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -316,7 +316,7 @@
<plugin>
<groupId>com.mycila.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
- <version>1.8.0</version>
+ <version>1.9.0</version>
<configuration>
<header>${topDirectoryLocation}/src/license/header.txt</header>
<aggregate>false</aggregate>
@@ -349,6 +349,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
<version>2.3</version>
+ <inherited>false</inherited>
<executions>
<execution>
<id>validate-changes</id>
@@ -378,7 +379,7 @@
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
- <version>6.1.21</version>
+ <version>6.1.26</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
@@ -388,7 +389,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- <version>1.4</version>
+ <version>2.0.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
@@ -423,9 +424,15 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
- <version>0.9.24</version>
+ <version>0.9.28</version>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.8.5</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
<profiles>
@@ -529,7 +536,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.7</version>
+ <version>2.7.2</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2011-01-27 13:15:39
|
Revision: 893
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=893&view=rev
Author: henryju
Date: 2011-01-27 13:15:33 +0000 (Thu, 27 Jan 2011)
Log Message:
-----------
Updated HtmlUnitTestingEngine to remove usage of deprecated HtmlUnit API.
Modified Paths:
--------------
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
Modified: trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
===================================================================
--- trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-01-27 13:03:38 UTC (rev 892)
+++ trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-01-27 13:15:33 UTC (rev 893)
@@ -19,6 +19,8 @@
package net.sourceforge.jwebunit.htmlunit;
+import org.apache.http.auth.AuthScope;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
@@ -410,7 +412,7 @@
}
public boolean hasFormParameterNamed(String paramName) {
- for (HtmlElement e : getCurrentPage().getAllHtmlChildElements()) {
+ for (HtmlElement e : getCurrentPage().getHtmlElementDescendants()) {
if (e.getAttribute("name").equals(paramName)) {
// set the working form if none has been set
if (e.getEnclosingForm() != null && getWorkingForm() == null)
@@ -430,7 +432,7 @@
public String getTextFieldValue(String paramName) {
// first try the current form
if (form != null) {
- for (HtmlElement e : form.getAllHtmlChildElements()) {
+ for (HtmlElement e : form.getHtmlElementDescendants()) {
if (e instanceof HtmlInput && e.getAttribute("name").equals(paramName)) {
// we found it
return ((HtmlInput) e).getValueAttribute();
@@ -474,7 +476,7 @@
public String getHiddenFieldValue(String paramName) {
// first try the current form
if (form != null) {
- for (HtmlElement e : form.getAllHtmlChildElements()) {
+ for (HtmlElement e : form.getHtmlElementDescendants()) {
if (e instanceof HtmlHiddenInput && e.getAttribute("name").equals(paramName)) {
// we found it
return ((HtmlInput) e).getValueAttribute();
@@ -507,7 +509,7 @@
public void setTextField(String paramName, String text) {
// first try the current form
if (form != null) {
- for (HtmlElement e : form.getAllHtmlChildElements()) {
+ for (HtmlElement e : form.getHtmlElementDescendants()) {
if (e instanceof HtmlInput && e.getAttribute("name").equals(paramName)) {
// we found it
((HtmlInput) e).setValueAttribute(text);
@@ -554,7 +556,7 @@
public void setHiddenField(String fieldName, String text) {
// first try the current form
if (form != null) {
- for (HtmlElement e : form.getAllHtmlChildElements()) {
+ for (HtmlElement e : form.getHtmlElementDescendants()) {
if (e instanceof HtmlHiddenInput && e.getAttribute("name").equals(fieldName)) {
// we found it
((HtmlHiddenInput) e).setValueAttribute(text);
@@ -694,7 +696,7 @@
public URL getPageURL() {
- return win.getEnclosedPage().getWebResponse().getRequestSettings().getUrl();
+ return win.getEnclosedPage().getWebResponse().getWebRequest().getUrl();
}
public String getPageSource() {
@@ -734,7 +736,7 @@
.getWebResponse();
result.append(wr.getStatusCode()).append(" ").append(
wr.getStatusMessage()).append("\n");
- result.append("Location: ").append(wr.getRequestSettings().getUrl()).append("\n");
+ result.append("Location: ").append(wr.getWebRequest().getUrl()).append("\n");
for (NameValuePair h : wr.getResponseHeaders()) {
result.append(h.getName()).append(": ").append(h.getValue())
.append("\n");
@@ -788,10 +790,8 @@
*/
BrowserVersion bv;
if (testContext.getUserAgent() != null) {
- bv = new BrowserVersion(
- BrowserVersion.NETSCAPE, "5.0 (Windows; en-US)",
- testContext.getUserAgent(),
- 3);
+ bv = BrowserVersion.FIREFOX_3;
+ bv.setUserAgent(testContext.getUserAgent());
} else {
bv = defaultBrowserVersion; // use default (which includes a full UserAgent string)
}
@@ -839,9 +839,9 @@
getTestContext().getDomain());
}
if (getTestContext().hasProxyAuthorization()) {
- creds.addProxyCredentials(getTestContext().getProxyUser(),
+ creds.addCredentials(getTestContext().getProxyUser(),
getTestContext().getProxyPasswd(), getTestContext()
- .getProxyHost(), getTestContext().getProxyPort());
+ .getProxyHost(), getTestContext().getProxyPort(), AuthScope.ANY_REALM);
}
wc.setCredentialsProvider(creds);
wc.addWebWindowListener(new WebWindowListener() {
@@ -1152,7 +1152,7 @@
* @return the element found, or null
*/
private HtmlElement getHtmlElementWithAttribute(String attributeName, String value) {
- for (HtmlElement e : getCurrentPage().getAllHtmlChildElements()) {
+ for (HtmlElement e : getCurrentPage().getHtmlElementDescendants()) {
if (e.getAttribute(attributeName).equals(value)) {
return e;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SourceForge.net <no...@so...> - 2011-01-27 13:05:20
|
Bugs item #3166502, was opened at 2011-01-27 13:05 Message generated for change (Comment added) made by henryju You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166502&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: HtmlUnit plugin >Group: Release 3.0 >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Harri (n116373) Assigned to: Julien HENRY (henryju) Summary: Index bug in HtmlUnitTestingEngineImpl.getLinkWithImage() Initial Comment: JWebUnit-htmlunit-plugin 2.4 and 2.5 versions have the following private method in HtmlUnitTestingEngineImpl private HtmlAnchor getLinkWithImage(String filename, int index) { return (HtmlAnchor) getHtmlElementByXPath("(//a[img[contains(@src,\"" + filename + "\")]])[" + index + 1 + "]"); } 'index + 1' part should have parenthesis around integers: (index + 1), as now this concatenates integers as Strings. Index=1 results [11] and index = 2 results [12]. Common case index=0 works as [01] by accident. ---------------------------------------------------------------------- >Comment By: Julien HENRY (henryju) Date: 2011-01-27 14:05 Message: Good catch. This code was not tested because no exposed method was using it. As a result I decided to add 3 new "indexed" methods: clickLinkWithImage, assertLinkPresentWithImage and assertLinkNotPresentWithImage Thanks ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166502&group_id=61302 |
|
From: <he...@us...> - 2011-01-27 13:03:45
|
Revision: 892
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=892&view=rev
Author: henryju
Date: 2011-01-27 13:03:38 +0000 (Thu, 27 Jan 2011)
Log Message:
-----------
[3166502] Added indexed alternatives of methods clickLinkWithImage, assertLinkPresentWithImage and assertLinkNotPresentWithImage to test and expose a bug in HtmlUnit testing engine.
Modified Paths:
--------------
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
trunk/jwebunit-commons-tests/src/main/resources/testcases/NavigationTest/pageWithLink.html
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
trunk/src/changes/changes.xml
Modified: trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
===================================================================
--- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java 2011-01-27 12:37:47 UTC (rev 891)
+++ trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java 2011-01-27 13:03:38 UTC (rev 892)
@@ -34,6 +34,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+
+import org.junit.Before;
+
import net.sourceforge.jwebunit.exception.TestingEngineResponseException;
import org.junit.Test;
@@ -47,20 +50,24 @@
*/
public class NavigationTest extends JWebUnitAPITestCase {
+ @Before
public void setUp() throws Exception {
super.setUp();
setBaseUrl(HOST_PATH + "/NavigationTest");
}
- @Test public void testBeginAtRelative() {
+ @Test
+ public void testBeginAtRelative() {
beginAt("/blah.html");
}
- @Test public void testBeginAtAbsolute() {
+ @Test
+ public void testBeginAtAbsolute() {
beginAt(HOST_PATH + "/NavigationTest/blah.html");
}
- @Test public void testForwardSlashConfusion() throws Exception {
+ @Test
+ public void testForwardSlashConfusion() throws Exception {
beginAt("/blah.html");
beginAt("blah.html");
getTestContext().setBaseUrl(HOST_PATH + "/NavigationTest/");
@@ -68,14 +75,16 @@
beginAt("blah.html");
}
- @Test public void testInvalidBeginAt() {
+ @Test
+ public void testInvalidBeginAt() {
//the testing engines should throw an exception if a 404 Error is found.
assertException(TestingEngineResponseException.class, "beginAt", new Object[] {"/nosuchresource.html"});
}
- @Test public void testClickLinkWithText() {
+ @Test
+ public void testClickLinkWithText() {
beginAt("/pageWithLink.html");
assertTitleEquals("pageWithLink");
@@ -106,7 +115,8 @@
assertTitleEquals("pageWithLink");
}
- @Test public void testClickLinkWithImage() {
+ @Test
+ public void testClickLinkWithImage() {
beginAt("/pageWithLink.html");
assertTitleEquals("pageWithLink");
@@ -114,7 +124,26 @@
assertTitleEquals("targetPage2");
}
- @Test public void testClickLinkByID() {
+ @Test
+ public void testClickLinkWithImageAnd0Index() {
+ beginAt("/pageWithLink.html");
+ assertTitleEquals("pageWithLink");
+
+ clickLinkWithImage("graphic.jpg", 0);
+ assertTitleEquals("targetPage2");
+ }
+
+ @Test
+ public void testClickLinkWithImageAnd1Index() {
+ beginAt("/pageWithLink.html");
+ assertTitleEquals("pageWithLink");
+
+ clickLinkWithImage("graphic.jpg", 1);
+ assertTitleEquals("targetPage");
+ }
+
+ @Test
+ public void testClickLinkByID() {
beginAt("/pageWithLink.html");
assertTitleEquals("pageWithLink");
@@ -122,7 +151,8 @@
assertTitleEquals("targetPage");
}
- @Test public void testInvalidClickLink() {
+ @Test
+ public void testInvalidClickLink() {
beginAt("/pageWithLink.html");
assertTitleEquals("pageWithLink");
@@ -134,14 +164,16 @@
fail("Expected exception");
}
- @Test public void testGotoPageRelative() {
+ @Test
+ public void testGotoPageRelative() {
beginAt("/targetPage.html");
assertTitleEquals("targetPage");
gotoPage("/targetPage2.html");
assertTitleEquals("targetPage2");
}
- @Test public void testGotoPageAbsolute() {
+ @Test
+ public void testGotoPageAbsolute() {
beginAt("/targetPage.html");
assertTitleEquals("targetPage");
gotoPage(HOST_PATH + "/NavigationTest/targetPage2.html");
@@ -149,7 +181,8 @@
}
//For bug 726143
- @Test public void testLinkWithEscapedText() {
+ @Test
+ public void testLinkWithEscapedText() {
beginAt("/pageWithAmpersandInLink.html");
assertLinkPresentWithText("Map & Directions");
clickLinkWithText("Map & Directions");
@@ -159,7 +192,8 @@
/**
* Testing for issue 996031
*/
- @Test public void testLinkExactText() {
+ @Test
+ public void testLinkExactText() {
beginAt("/test1.html");
assertTitleEquals("test1");
assertLinkPresentWithExactText("one");
Modified: trunk/jwebunit-commons-tests/src/main/resources/testcases/NavigationTest/pageWithLink.html
===================================================================
--- trunk/jwebunit-commons-tests/src/main/resources/testcases/NavigationTest/pageWithLink.html 2011-01-27 12:37:47 UTC (rev 891)
+++ trunk/jwebunit-commons-tests/src/main/resources/testcases/NavigationTest/pageWithLink.html 2011-01-27 13:03:38 UTC (rev 892)
@@ -29,5 +29,8 @@
<img src="graphic.jpg"/>
</a>
<a href="/jwebunit/NavigationTest/targetPage2.html">an active <i>link</i></a>
+ <a href="/jwebunit/NavigationTest/targetPage.html">
+ <img src="graphic.jpg"/>
+ </a>
</body>
</html>
\ No newline at end of file
Modified: trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 2011-01-27 12:37:47 UTC (rev 891)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 2011-01-27 13:03:38 UTC (rev 892)
@@ -2035,18 +2035,44 @@
}
/**
+ * Assert that a link containing a specified image is present.
+ *
+ * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>,
+ * you could just pass in <tt>"my_icon.png"</tt>.
+ * @param index The 0-based index, when more than one link with the same image is expected.
+ */
+ public void assertLinkPresentWithImage(String imageFileName, int index) {
+ assertTrue("Link with image file [" + imageFileName
+ + "] and index " + index + " not found in response.", getTestingEngine()
+ .hasLinkWithImage(imageFileName, index));
+ }
+
+ /**
* Assert that a link containing a specified image is not present.
*
* @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>,
* you could just pass in <tt>"my_icon.png"</tt>.
*/
public void assertLinkNotPresentWithImage(String imageFileName) {
- assertTrue("Link with image file [" + imageFileName
- + "] found in response.", !getTestingEngine().hasLinkWithImage(
+ assertFalse("Link with image file [" + imageFileName
+ + "] found in response.", getTestingEngine().hasLinkWithImage(
imageFileName, 0));
}
/**
+ * Assert that a link containing a specified image is not present.
+ *
+ * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>,
+ * you could just pass in <tt>"my_icon.png"</tt>.
+ * @param index The 0-based index, when more than one link with the same image is expected.
+ */
+ public void assertLinkNotPresentWithImage(String imageFileName, int index) {
+ assertFalse("Link with image file [" + imageFileName
+ + "] and index " + index + " found in response.",
+ getTestingEngine().hasLinkWithImage(imageFileName, index));
+ }
+
+ /**
* Assert that an element with a given id is present.
*
* @param anID element id to test for.
@@ -2601,6 +2627,18 @@
}
/**
+ * Navigate by selection of a link with a given image.
+ *
+ * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>,
+ * you could just pass in <tt>"my_icon.png"</tt>.
+ * @param index The 0-based index, when more than one link with the same image is expected.
+ */
+ public void clickLinkWithImage(String imageFileName, int index) {
+ assertLinkPresentWithImage(imageFileName, index);
+ getTestingEngine().clickLinkWithImage(imageFileName, index);
+ }
+
+ /**
* Navigate by selection of a link with given id.
*
* @param linkId id of link
Modified: trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java
===================================================================
--- trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-01-27 12:37:47 UTC (rev 891)
+++ trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-01-27 13:03:38 UTC (rev 892)
@@ -1822,7 +1822,7 @@
private HtmlAnchor getLinkWithImage(String filename, int index) {
return (HtmlAnchor) getHtmlElementByXPath("(//a[img[contains(@src,\""
- + filename + "\")]])[" + index + 1 + "]");
+ + filename + "\")]])[" + (index + 1) + "]");
}
private HtmlAnchor getLinkWithText(String linkText, int index) {
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2011-01-27 12:37:47 UTC (rev 891)
+++ trunk/src/changes/changes.xml 2011-01-27 13:03:38 UTC (rev 892)
@@ -32,6 +32,9 @@
</properties>
<body>
<release version="3.0" date="UNKNOW" description="Updated all internals to JUnit 4">
+ <action type="add" dev="henryju" issue="3166502" due-to="Harri">
+ Added indexed alternatives of methods clickLinkWithImage, assertLinkPresentWithImage and assertLinkNotPresentWithImage.
+ </action>
<action type="fix" dev="henryju" issue="3116839" due-to="Tony Qian">
assertTitleNotSame works incorrectly. Deprecated and replaced by a working assertTitleNotEquals.
</action>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2011-01-27 12:37:54
|
Revision: 891
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=891&view=rev
Author: henryju
Date: 2011-01-27 12:37:47 +0000 (Thu, 27 Jan 2011)
Log Message:
-----------
Disabled toolchains in Eclipse with M2Eclipse because of bug MNGECLIPSE-2215.
Modified Paths:
--------------
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-12-22 09:30:28 UTC (rev 890)
+++ trunk/pom.xml 2011-01-27 12:37:47 UTC (rev 891)
@@ -489,6 +489,24 @@
</plugins>
</build>
</profile>
+ <profile>
+ <id>m2e</id>
+ <activation>
+ <property>
+ <name>m2e.version</name><!-- Activate only when within eclipse -->
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <!-- Set to false to work around Maven Eclipse plugin (m2e) bug MNGECLIPSE-2215 -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <inherited>false</inherited>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
<reporting>
<plugins>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SourceForge.net <no...@so...> - 2011-01-27 12:32:09
|
Bugs item #3166502, was opened at 2011-01-27 13:05 Message generated for change (Settings changed) made by henryju You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166502&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: HtmlUnit plugin Group: Release 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Harri (n116373) >Assigned to: Julien HENRY (henryju) Summary: Index bug in HtmlUnitTestingEngineImpl.getLinkWithImage() Initial Comment: JWebUnit-htmlunit-plugin 2.4 and 2.5 versions have the following private method in HtmlUnitTestingEngineImpl private HtmlAnchor getLinkWithImage(String filename, int index) { return (HtmlAnchor) getHtmlElementByXPath("(//a[img[contains(@src,\"" + filename + "\")]])[" + index + 1 + "]"); } 'index + 1' part should have parenthesis around integers: (index + 1), as now this concatenates integers as Strings. Index=1 results [11] and index = 2 results [12]. Common case index=0 works as [01] by accident. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166502&group_id=61302 |
|
From: SourceForge.net <no...@so...> - 2011-01-27 12:05:57
|
Bugs item #3166502, was opened at 2011-01-27 14:05 Message generated for change (Tracker Item Submitted) made by n116373 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166502&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: HtmlUnit plugin Group: Release 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Harri (n116373) Assigned to: Nobody/Anonymous (nobody) Summary: Index bug in HtmlUnitTestingEngineImpl.getLinkWithImage() Initial Comment: JWebUnit-htmlunit-plugin 2.4 and 2.5 versions have the following private method in HtmlUnitTestingEngineImpl private HtmlAnchor getLinkWithImage(String filename, int index) { return (HtmlAnchor) getHtmlElementByXPath("(//a[img[contains(@src,\"" + filename + "\")]])[" + index + 1 + "]"); } 'index + 1' part should have parenthesis around integers: (index + 1), as now this concatenates integers as Strings. Index=1 results [11] and index = 2 results [12]. Common case index=0 works as [01] by accident. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3166502&group_id=61302 |
|
From: <he...@us...> - 2010-12-22 09:30:34
|
Revision: 890
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=890&view=rev
Author: henryju
Date: 2010-12-22 09:30:28 +0000 (Wed, 22 Dec 2010)
Log Message:
-----------
Updated m-surefire-p and m-dep-info-report-p versions.
Modified Paths:
--------------
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-11-29 16:19:05 UTC (rev 889)
+++ trunk/pom.xml 2010-12-22 09:30:28 UTC (rev 890)
@@ -226,7 +226,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.6</version>
+ <version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -511,7 +511,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.6</version>
+ <version>2.7</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
@@ -613,7 +613,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
- <version>2.2</version>
+ <version>2.3.1</version>
<reportSets>
<reportSet>
<reports>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2010-11-29 16:19:11
|
Revision: 889
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=889&view=rev
Author: henryju
Date: 2010-11-29 16:19:05 +0000 (Mon, 29 Nov 2010)
Log Message:
-----------
Updated site plugin for Maven 2.2.1, minor doc fixes, plugin version lock.
Modified Paths:
--------------
trunk/pom.xml
trunk/src/site/xdoc/how-to-release.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-11-24 16:13:09 UTC (rev 888)
+++ trunk/pom.xml 2010-11-29 16:19:05 UTC (rev 889)
@@ -210,6 +210,21 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>2.4.1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>2.3.1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
</plugin>
@@ -264,7 +279,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
- <version>2.1.1</version>
+ <version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Modified: trunk/src/site/xdoc/how-to-release.xml
===================================================================
--- trunk/src/site/xdoc/how-to-release.xml 2010-11-24 16:13:09 UTC (rev 888)
+++ trunk/src/site/xdoc/how-to-release.xml 2010-11-29 16:19:05 UTC (rev 889)
@@ -33,16 +33,16 @@
<subsection name="Last checks and updates">
<p>
<ul>
- <li>Ensure you repository is up to date by running: <tt>svn update</tt></li>
- <li>Edit <tt>src/changes/changes.xml</tt> to set release date instead of "unknow"</li>
+ <li>Ensure your repository is up to date by running: <tt>svn update</tt></li>
+ <li>Edit <tt>src/changes/changes.xml</tt> to set the release date instead of "unknow"</li>
<li>Update readme.txt (at least update the version number)</li>
<li>Update JWebUnit latest version in src/site/xdoc/index.xml, src/site/xdoc/installation.xml, jwebunit-htmlunit-plugin/src/site/xdoc/index.xml, jwebunit-selenium-plugin/src/site/xdoc/index.xml</li>
<li>Commit the changes</li>
</ul>
</p>
<p>
- Now check that in your <tt>settings.xml</tt> (usually in <tt>$M2_HOME/conf</tt> or better in <tt>~/.m2</tt>
- your JWebUnit details are correct:
+ Now check that in your <tt>settings.xml</tt> (usually in <tt>~/.m2</tt>)
+ the JWebUnit server details are correct:
<source><![CDATA[
<server>
<id>jwebunit-website</id>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|