Thread: [JWebUnit-development] SF.net SVN: jwebunit:[817] trunk/jwebunit-htmlunit-plugin/src/main/java/net
Brought to you by:
henryju
|
From: <he...@us...> - 2009-12-15 13:05:44
|
Revision: 817
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=817&view=rev
Author: henryju
Date: 2009-12-15 13:05:33 +0000 (Tue, 15 Dec 2009)
Log Message:
-----------
Fixed cast error reported by findbugs.
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 2009-11-30 16:14:19 UTC (rev 816)
+++ trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2009-12-15 13:05:33 UTC (rev 817)
@@ -63,6 +63,7 @@
import com.gargoylesoftware.htmlunit.WebWindowEvent;
import com.gargoylesoftware.htmlunit.WebWindowListener;
import com.gargoylesoftware.htmlunit.WebWindowNotFoundException;
+import com.gargoylesoftware.htmlunit.html.ClickableElement;
import com.gargoylesoftware.htmlunit.html.DomComment;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.FrameWindow;
@@ -1163,7 +1164,7 @@
return null;
}
- public HtmlResetInput getResetButton(String buttonName) {
+ public ClickableElement getResetButton(String buttonName) {
List<HtmlElement> btns = new LinkedList<HtmlElement>();
if (form != null) {
btns.addAll(getForm().getInputsByName(buttonName));
@@ -1181,7 +1182,7 @@
return btn;
}
if (o instanceof HtmlButton) {
- HtmlResetInput btn = (HtmlResetInput) o;
+ HtmlButton btn = (HtmlButton) o;
if (btn.getTypeAttribute().equals("reset")) {
if (form == null) {
form = btn.getEnclosingFormOrDie();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2010-11-10 11:15:48
|
Revision: 887
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=887&view=rev
Author: henryju
Date: 2010-11-10 11:15:41 +0000 (Wed, 10 Nov 2010)
Log Message:
-----------
Fixed some code style to please Sonar
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 2010-10-27 08:41:56 UTC (rev 886)
+++ trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2010-11-10 11:15:41 UTC (rev 887)
@@ -154,22 +154,22 @@
/**
* Javascript alerts.
*/
- private LinkedList<JavascriptAlert> expectedJavascriptAlerts = new LinkedList<JavascriptAlert>();
+ private List<JavascriptAlert> expectedJavascriptAlerts = new LinkedList<JavascriptAlert>();
/**
* Javascript confirms.
*/
- private LinkedList<JavascriptConfirm> expectedJavascriptConfirms = new LinkedList<JavascriptConfirm>();
+ private List<JavascriptConfirm> expectedJavascriptConfirms = new LinkedList<JavascriptConfirm>();
/**
* Javascript prompts.
*/
- private LinkedList<JavascriptPrompt> expectedJavascriptPrompts = new LinkedList<JavascriptPrompt>();
+ private List<JavascriptPrompt> expectedJavascriptPrompts = new LinkedList<JavascriptPrompt>();
/**
* The default browser version.
*/
- BrowserVersion defaultBrowserVersion = BrowserVersion.FIREFOX_3;
+ private BrowserVersion defaultBrowserVersion = BrowserVersion.FIREFOX_3;
/**
* Should we ignore failing status codes?
@@ -603,23 +603,24 @@
*/
public String[] getSelectOptionValues(String selectName, int index) {
List<HtmlSelect> sels = getForm().getSelectsByName(selectName);
- if ( sels == null || sels.size() < index+1)
- throw new RuntimeException("Did not find select with name [" + selectName
+ if ( sels == null || sels.size() < index+1) {
+ throw new RuntimeException("Did not find select with name [" + selectName
+ "] at index " + index);
-
+ }
HtmlSelect sel = sels.get(index);
ArrayList<String> result = new ArrayList<String>();
for (HtmlOption opt : sel.getOptions()) {
result.add(opt.getValueAttribute());
}
- return (String[]) result.toArray(new String[0]);
+ return (String[]) result.toArray(new String[result.size()]);
}
private String[] getSelectedOptions(HtmlSelect sel) {
String[] result = new String[sel.getSelectedOptions().size()];
int i = 0;
- for (HtmlOption opt : sel.getSelectedOptions())
+ for (HtmlOption opt : sel.getSelectedOptions()) {
result[i++] = opt.getValueAttribute();
+ }
return result;
}
@@ -631,9 +632,10 @@
public String[] getSelectedOptions(String selectName, int index) {
List<HtmlSelect> sels = getForm().getSelectsByName(selectName);
- if ( sels == null || sels.size() < index+1)
- throw new RuntimeException("Did not find select with name [" + selectName
+ if ( sels == null || sels.size() < index+1) {
+ throw new RuntimeException("Did not find select with name [" + selectName
+ "] at index " + index);
+ }
HtmlSelect sel = sels.get(index);
return getSelectedOptions(sel);
}
@@ -641,8 +643,9 @@
private String getSelectOptionValueForLabel(HtmlSelect sel, String label) {
for (HtmlOption opt : sel.getOptions()) {
- if (opt.asText().equals(label))
+ if (opt.asText().equals(label)) {
return opt.getValueAttribute();
+ }
}
throw new RuntimeException("Unable to find option " + label + " for "
+ sel.getNameAttribute());
@@ -655,17 +658,19 @@
public String getSelectOptionValueForLabel(String selectName, int index, String label) {
List<HtmlSelect> sels = getForm().getSelectsByName(selectName);
- if ( sels == null || sels.size() < index+1)
- throw new RuntimeException("Did not find select with name [" + selectName
+ if ( sels == null || sels.size() < index+1) {
+ throw new RuntimeException("Did not find select with name [" + selectName
+ "] at index " + index);
+ }
HtmlSelect sel = (HtmlSelect)sels.get(index);
return getSelectOptionValueForLabel(sel, label);
}
private String getSelectOptionLabelForValue(HtmlSelect sel, String value) {
for (HtmlOption opt : sel.getOptions()) {
- if (opt.getValueAttribute().equals(value))
+ if (opt.getValueAttribute().equals(value)) {
return opt.asText();
+ }
}
throw new RuntimeException("Unable to find option " + value + " for "
+ sel.getNameAttribute());
@@ -678,10 +683,10 @@
public String getSelectOptionLabelForValue(String selectName, int index, String value) {
List<HtmlSelect> sels = getForm().getSelectsByName(selectName);
- if ( sels == null || sels.size() < index+1)
- throw new RuntimeException("Did not find select with name [" + selectName
+ if ( sels == null || sels.size() < index+1) {
+ throw new RuntimeException("Did not find select with name [" + selectName
+ "] at index " + index);
-
+ }
HtmlSelect sel = (HtmlSelect)sels.get(index);
return getSelectOptionLabelForValue(sel, value);
}
@@ -703,17 +708,22 @@
public String getPageText() {
Page page = win.getEnclosedPage();
- if (page instanceof HtmlPage)
+ if (page instanceof HtmlPage) {
return ((HtmlPage) page).asText();
- if (page instanceof TextPage)
+ }
+ if (page instanceof TextPage) {
return ((TextPage) page).getContent();
- if (page instanceof JavaScriptPage)
+ }
+ if (page instanceof JavaScriptPage) {
return ((JavaScriptPage) page).getContent();
- if (page instanceof XmlPage)
+ }
+ if (page instanceof XmlPage) {
return ((XmlPage) page).getContent();
- if (page instanceof UnexpectedPage)
+ }
+ if (page instanceof UnexpectedPage) {
return ((UnexpectedPage) page).getWebResponse()
.getContentAsString();
+ }
throw new RuntimeException(
"Unexpected error in getPageText(). This method need to be updated.");
}
@@ -855,18 +865,20 @@
Page oldPage = event.getOldPage();
Page newPage = event.getNewPage();
String oldPageTitle = "no_html";
- if (oldPage instanceof HtmlPage)
+ if (oldPage instanceof HtmlPage) {
oldPageTitle = ((HtmlPage) oldPage).getTitleText();
+ }
String newPageTitle = "no_html";
- if (newPage instanceof HtmlPage)
+ if (newPage instanceof HtmlPage) {
newPageTitle = ((HtmlPage) newPage).getTitleText();
+ }
logger.debug("Window \"{}\" changed : \"{}\" became \"{}", new Object[] {winName, oldPageTitle, newPageTitle});
}
public void webWindowOpened(WebWindowEvent event) {
String win = event.getWebWindow().getName();
Page newPage = event.getNewPage();
- if (newPage != null && newPage instanceof HtmlPage) {
+ if (newPage instanceof HtmlPage) {
logger.debug("Window {} opened : {}", win, ((HtmlPage) newPage).getTitleText());
} else {
logger.info("Window {} opened", win);
@@ -880,7 +892,7 @@
throw new UnexpectedJavascriptAlertException(msg);
} else {
JavascriptAlert expected = (JavascriptAlert) expectedJavascriptAlerts
- .removeFirst();
+ .remove(0);
if (!msg.equals(expected.getMessage())) {
throw new UnexpectedJavascriptAlertException(msg);
}
@@ -894,7 +906,7 @@
throw new UnexpectedJavascriptConfirmException(msg);
} else {
JavascriptConfirm expected = (JavascriptConfirm) expectedJavascriptConfirms
- .removeFirst();
+ .remove(0);
if (!msg.equals(expected.getMessage())) {
throw new UnexpectedJavascriptConfirmException(msg);
} else {
@@ -910,7 +922,7 @@
throw new UnexpectedJavascriptPromptException(msg);
} else {
JavascriptPrompt expected = (JavascriptPrompt) expectedJavascriptPrompts
- .removeFirst();
+ .remove(0);
if (!msg.equals(expected.getMessage())) {
throw new UnexpectedJavascriptPromptException(msg);
} else {
@@ -1104,14 +1116,16 @@
private HtmlPage getCurrentPage() {
Page page = win.getEnclosedPage();
- if (page instanceof HtmlPage)
+ if (page instanceof HtmlPage) {
return (HtmlPage) page;
+ }
throw new RuntimeException("Non HTML content");
}
private void setWorkingForm(HtmlForm newForm) {
- if (newForm == null)
+ if (newForm == null) {
throw new UnableToSetFormException("Attempted to set form to null.");
+ }
form = newForm;
}
@@ -1137,13 +1151,14 @@
* @param value value to search for
* @return the element found, or null
*/
- private HtmlElement getHtmlElementWithAttribute(String attributeName, String value) {
- for (HtmlElement e : getCurrentPage().getAllHtmlChildElements()) {
- if (e.getAttribute(attributeName).equals(value))
- return e;
- }
- return null;
- }
+ private HtmlElement getHtmlElementWithAttribute(String attributeName, String value) {
+ for (HtmlElement e : getCurrentPage().getAllHtmlChildElements()) {
+ if (e.getAttribute(attributeName).equals(value)) {
+ return e;
+ }
+ }
+ return null;
+ }
/**
* Return true if a form parameter (input element) is present on the current response.
@@ -1328,8 +1343,9 @@
btn = getCurrentPage().getHtmlElementById(buttonId);
if (btn instanceof HtmlButton || btn instanceof HtmlButtonInput
|| btn instanceof HtmlSubmitInput
- || btn instanceof HtmlResetInput)
+ || btn instanceof HtmlResetInput) {
return btn;
+ }
} catch (ElementNotFoundException e) {
return null;
}
@@ -1365,17 +1381,17 @@
.getHtmlElementsByTagNames(
Arrays.asList(new String[] { "button", "input" }));
for (HtmlElement e : l) {
- if ( e instanceof HtmlButton )
- {
- if (((HtmlButton) e).asText().equals(buttonValueText))
- return e;
+ if ( e instanceof HtmlButton ) {
+ if (((HtmlButton) e).asText().equals(buttonValueText)) {
+ return e;
+ }
}
else if ( e instanceof HtmlButtonInput ||
e instanceof HtmlSubmitInput ||
- e instanceof HtmlResetInput )
- {
- if ( buttonValueText.equals(e.getAttribute("value")) )
- return e;
+ e instanceof HtmlResetInput ) {
+ if ( buttonValueText.equals(e.getAttribute("value")) ) {
+ return e;
+ }
}
}
return null;
@@ -1422,8 +1438,9 @@
HtmlTableCell cell = table.getCellAt(row, col);
if (cell != null) {
String cellHtml = cell.asText();
- if (cellHtml.indexOf(text) != -1)
+ if (cellHtml.indexOf(text) != -1) {
return true;
+ }
}
}
}
@@ -1502,10 +1519,10 @@
} catch (FailingHttpStatusCodeException e) {
// entirely possible that it can fail here
- if (!ignoreFailingStatusCodes)
+ if (!ignoreFailingStatusCodes) {
throw new TestingEngineResponseException(
e.getStatusCode(), e);
-
+ }
return;
} catch (IOException e) {
throw new RuntimeException(
@@ -1599,10 +1616,10 @@
}
} catch (FailingHttpStatusCodeException e) {
// entirely possible that it can fail here
- if (!ignoreFailingStatusCodes)
+ if (!ignoreFailingStatusCodes) {
throw new TestingEngineResponseException(
e.getStatusCode(), e);
-
+ }
return;
} catch (IOException e) {
throw new RuntimeException(
@@ -1658,9 +1675,10 @@
public void clickLinkWithText(String linkText, int index) {
HtmlAnchor link = getLinkWithText(linkText, index);
- if (link == null)
+ if (link == null) {
throw new RuntimeException("No Link found for \"" + linkText
+ "\" with index " + index);
+ }
try {
link.click();
} catch (IOException e) {
@@ -1670,9 +1688,10 @@
public void clickLinkWithExactText(String linkText, int index) {
HtmlAnchor link = getLinkWithExactText(linkText, index);
- if (link == null)
+ if (link == null) {
throw new RuntimeException("No Link found for \"" + linkText
+ "\" with index " + index);
+ }
try {
link.click();
} catch (IOException e) {
@@ -1683,8 +1702,9 @@
private HtmlCheckBoxInput getCheckbox(String checkBoxName) {
Object[] l = getForm().getInputsByName(checkBoxName).toArray();
for (int i = 0; i < l.length; i++) {
- if (l[i] instanceof HtmlCheckBoxInput)
+ if (l[i] instanceof HtmlCheckBoxInput) {
return (HtmlCheckBoxInput) l[i];
+ }
}
throw new RuntimeException("No checkbox with name [" + checkBoxName
+ "] was found in current form.");
@@ -1693,10 +1713,11 @@
private HtmlCheckBoxInput getCheckbox(String checkBoxName, String value) {
Object[] l = getForm().getInputsByName(checkBoxName).toArray();
for (int i = 0; i < l.length; i++) {
- if (l[i] instanceof HtmlCheckBoxInput)
- if (((HtmlCheckBoxInput) l[i]).getValueAttribute()
- .equals(value))
- return (HtmlCheckBoxInput) l[i];
+ if ((l[i] instanceof HtmlCheckBoxInput) &&
+ ((HtmlCheckBoxInput) l[i]).getValueAttribute()
+ .equals(value)) {
+ return (HtmlCheckBoxInput) l[i];
+ }
}
throw new RuntimeException("No checkbox with name [" + checkBoxName
+ "] and value [" + value + "] was found in current form.");
@@ -1709,23 +1730,25 @@
*/
public void checkCheckbox(String checkBoxName) {
HtmlCheckBoxInput cb = getCheckbox(checkBoxName);
- if (!cb.isChecked())
+ if (!cb.isChecked()) {
try {
cb.click();
} catch (IOException e) {
throw new RuntimeException("checkCheckbox failed", e);
}
+ }
}
public void checkCheckbox(String checkBoxName, String value) {
HtmlCheckBoxInput cb = getCheckbox(checkBoxName, value);
- if (!cb.isChecked())
+ if (!cb.isChecked()) {
try {
cb.click();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("checkCheckbox failed", e);
}
+ }
}
/**
@@ -1735,24 +1758,26 @@
*/
public void uncheckCheckbox(String checkBoxName) {
HtmlCheckBoxInput cb = getCheckbox(checkBoxName);
- if (cb.isChecked())
+ if (cb.isChecked()) {
try {
cb.click();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("checkCheckbox failed", e);
}
+ }
}
public void uncheckCheckbox(String checkBoxName, String value) {
HtmlCheckBoxInput cb = getCheckbox(checkBoxName, value);
- if (cb.isChecked())
+ if (cb.isChecked()) {
try {
cb.click();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("uncheckCheckbox failed", e);
}
+ }
}
private HtmlRadioButtonInput getRadioOption(String radioGroup, String radioOption) {
@@ -1775,13 +1800,14 @@
*/
public void clickRadioOption(String radioGroup, String radioOption) {
HtmlRadioButtonInput rb = getRadioOption(radioGroup, radioOption);
- if (!rb.isChecked())
+ if (!rb.isChecked()) {
try {
rb.click();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("checkCheckbox failed", e);
}
+ }
}
/**
@@ -1803,8 +1829,9 @@
List<HtmlAnchor> lnks = ((HtmlPage) win.getEnclosedPage()).getAnchors();
int count = 0;
for (HtmlAnchor lnk : lnks) {
- if ((lnk.asText().indexOf(linkText) >= 0) && (count++ == index))
+ if ((lnk.asText().indexOf(linkText) >= 0) && (count++ == index)) {
return lnk;
+ }
}
return null;
}
@@ -1813,8 +1840,9 @@
List<HtmlAnchor> lnks = ((HtmlPage) win.getEnclosedPage()).getAnchors();
int count = 0;
for (HtmlAnchor lnk : lnks) {
- if ((lnk.asText().equals(linkText)) && (count++ == index))
+ if ((lnk.asText().equals(linkText)) && (count++ == index)) {
return lnk;
+ }
}
return null;
}
@@ -1829,9 +1857,10 @@
*/
public void clickLinkWithImage(String imageFileName, int index) {
HtmlAnchor link = getLinkWithImage(imageFileName, index);
- if (link == null)
+ if (link == null) {
throw new RuntimeException("No Link found with filename \""
+ imageFileName + "\" and index " + index);
+ }
try {
link.click();
} catch (IOException e) {
@@ -1849,9 +1878,10 @@
public void clickElementByXPath(String xpath) {
HtmlElement e = getHtmlElementByXPath(xpath);
- if (e == null)
+ if (e == null) {
throw new RuntimeException("No element found with xpath \"" + xpath
+ "\"");
+ }
try {
e.click();
} catch (IOException exp) {
@@ -1861,16 +1891,18 @@
public String getElementAttributByXPath(String xpath, String attribut) {
HtmlElement e = getHtmlElementByXPath(xpath);
- if (e == null)
+ if (e == null) {
return null;
+ }
return e.getAttribute(attribut);
}
public String getElementTextByXPath(String xpath) {
HtmlElement e = getHtmlElementByXPath(xpath);
- if (e == null)
+ if (e == null) {
return null;
+ }
return e.asText();
}
@@ -1897,17 +1929,17 @@
* content by converting it to text. or an HTML <button> tag.
*/
public void clickButtonWithText(String buttonValueText) {
- HtmlElement b = getButtonWithText(buttonValueText);
- if (b != null) {
- try {
- b.click();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- else {
- throw new RuntimeException("No button found with text: " + buttonValueText);
- }
+ HtmlElement b = getButtonWithText(buttonValueText);
+ if (b != null) {
+ try {
+ b.click();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ else {
+ throw new RuntimeException("No button found with text: " + buttonValueText);
+ }
}
/**
@@ -1923,9 +1955,9 @@
public String getSelectedRadio(String radioGroup) {
List<HtmlRadioButtonInput> radios = getForm().getRadioButtonsByName(radioGroup);
for (HtmlRadioButtonInput radio : radios) {
- if (radio.isChecked()) {
- return radio.getValueAttribute();
- }
+ if (radio.isChecked()) {
+ return radio.getValueAttribute();
+ }
}
throw new RuntimeException("Unexpected state: no radio button was selected in radio group ["+radioGroup+"]. Is it possible in a real browser?");
}
@@ -1940,8 +1972,9 @@
String[] opts = getSelectOptionValues(selectName);
for (int i = 0; i < opts.length; i++) {
String label = getSelectOptionLabelForValue(selectName, opts[i]);
- if (label.equals(optionLabel))
+ if (label.equals(optionLabel)) {
return true;
+ }
}
return false;
}
@@ -1955,8 +1988,9 @@
public boolean hasSelectOptionValue(String selectName, String optionValue) {
String[] opts = getSelectOptionValues(selectName);
for (int i = 0; i < opts.length; i++) {
- if (opts[i].equals(optionValue))
+ if (opts[i].equals(optionValue)) {
return true;
+ }
}
return false;
}
@@ -1980,9 +2014,10 @@
break;
}
}
- if (!found)
+ if (!found) {
throw new RuntimeException("Option " + option
+ " not found");
+ }
}
}
@@ -1998,8 +2033,9 @@
String[] opts = getSelectOptionValues(selectName, index);
for (int i = 0; i < opts.length; i++) {
String label = getSelectOptionLabelForValue(selectName, index, opts[i]);
- if (label.equals(optionLabel))
+ if (label.equals(optionLabel)) {
return true;
+ }
}
return false;
}
@@ -2015,8 +2051,9 @@
public boolean hasSelectOptionValue(String selectName, int index, String optionValue) {
String[] opts = getSelectOptionValues(selectName, index);
for (int i = 0; i < opts.length; i++) {
- if (opts[i].equals(optionValue))
+ if (opts[i].equals(optionValue)) {
return true;
+ }
}
return false;
}
@@ -2031,12 +2068,14 @@
*/
public void selectOptions(String selectName, int index, String[] options) {
List<HtmlSelect> sels = getForm().getSelectsByName(selectName);
- if ( sels == null || sels.size() < index+1 )
- throw new RuntimeException("Did not find select with name [" + selectName
- + "] at index " + index);
+ if ( sels == null || sels.size() < index+1 ) {
+ throw new RuntimeException("Did not find select with name [" + selectName
+ + "] at index " + index);
+ }
HtmlSelect sel = (HtmlSelect)sels.get(index);
- if (!sel.isMultipleSelectEnabled() && options.length > 1)
+ if (!sel.isMultipleSelectEnabled() && options.length > 1) {
throw new RuntimeException("Multiselect not enabled");
+ }
for (String option : options) {
boolean found = false;
for (HtmlOption opt : sel.getOptions()) {
@@ -2046,17 +2085,19 @@
break;
}
}
- if (!found)
+ if (!found) {
throw new RuntimeException("Option " + option
+ " not found");
+ }
}
}
public void unselectOptions(String selectName, String[] options) {
HtmlSelect sel = getForm().getSelectByName(selectName);
- if (!sel.isMultipleSelectEnabled() && options.length > 1)
+ if (!sel.isMultipleSelectEnabled() && options.length > 1) {
throw new RuntimeException("Multiselect not enabled");
+ }
for (String option : options) {
boolean found = false;
for (HtmlOption opt : sel.getOptions()) {
@@ -2066,19 +2107,22 @@
break;
}
}
- if (!found)
+ if (!found) {
throw new RuntimeException("Option " + option
+ " not found");
+ }
}
}
public void unselectOptions(String selectName, int index, String[] options) {
List<HtmlSelect> sels = getForm().getSelectsByName(selectName);
- if ( sels == null || sels.size() < index+1)
- throw new RuntimeException("Did not find select with name [" + selectName
- + "] at index " + index);
+ if ( sels == null || sels.size() < index+1) {
+ throw new RuntimeException("Did not find select with name [" + selectName
+ + "] at index " + index);
+ }
HtmlSelect sel = sels.get(index);
- if (!sel.isMultipleSelectEnabled() && options.length > 1)
+ if (!sel.isMultipleSelectEnabled() && options.length > 1) {
throw new RuntimeException("Multiselect not enabled");
+ }
for (String option : options) {
boolean found = false;
for (HtmlOption opt : sel.getOptions()) {
@@ -2088,9 +2132,10 @@
break;
}
}
- if (!found)
+ if (!found) {
throw new RuntimeException("Option " + option
+ " not found");
+ }
}
}
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: <he...@us...> - 2011-09-23 14:33:55
|
Revision: 919
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=919&view=rev
Author: henryju
Date: 2011-09-23 14:33:49 +0000 (Fri, 23 Sep 2011)
Log Message:
-----------
Some minor fixes to HtmlUnit discovered while coding WebDriver testing engine.
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-09-23 14:19:55 UTC (rev 918)
+++ trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-09-23 14:33:49 UTC (rev 919)
@@ -18,6 +18,8 @@
*/
package net.sourceforge.jwebunit.htmlunit;
+import com.gargoylesoftware.htmlunit.TopLevelWindow;
+
import net.sourceforge.jwebunit.api.HttpHeader;
import org.apache.http.auth.AuthScope;
@@ -350,6 +352,9 @@
if (window != null) {
setMainWindow(window);
}
+ else {
+ throw new RuntimeException("No window found with title [" + title + "]");
+ }
}
/**
@@ -357,7 +362,7 @@
*/
public void closeWindow() {
if (win != null) {
- wc.deregisterWebWindow(win);
+ ((TopLevelWindow) win.getTopWindow()).close();
win = wc.getCurrentWindow();
form = null;
}
@@ -712,7 +717,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();
@@ -791,7 +796,7 @@
*/
BrowserVersion bv;
if (testContext.getUserAgent() != null) {
- bv = BrowserVersion.FIREFOX_3;
+ bv = BrowserVersion.FIREFOX_3_6;
bv.setUserAgent(testContext.getUserAgent());
} else {
bv = defaultBrowserVersion; // use default (which includes a full UserAgent string)
@@ -1462,8 +1467,8 @@
return false;
}
- public Table getTable(String tableSummaryOrId) {
- HtmlTable table = getHtmlTable(tableSummaryOrId);
+ public Table getTable(String tableSummaryNameOrId) {
+ HtmlTable table = getHtmlTable(tableSummaryNameOrId);
Table result = new Table();
for (int i = 0; i < table.getRowCount(); i++) {
Row newRow = new Row();
@@ -1480,31 +1485,37 @@
}
/**
- * Return the HttpUnit WebTable object representing a specified table in the current response. Null is returned if a
+ * Return the HtmlUnit WebTable object representing a specified table in the current response. Null is returned if a
* parsing exception occurs looking for the table or no table with the id or summary could be found.
*
- * @param tableSummaryOrId summary or id of the table to return.
+ * @param tableSummaryNameOrId summary or id of the table to return.
*/
- public HtmlTable getHtmlTable(String tableSummaryOrId) {
+ private HtmlTable getHtmlTable(String tableSummaryNameOrId) {
try {
return (HtmlTable) ((HtmlPage) win.getEnclosedPage())
- .getHtmlElementById(tableSummaryOrId);
+ .getHtmlElementById(tableSummaryNameOrId);
} catch (ElementNotFoundException e) {
-
+ //Not found
}
try {
return (HtmlTable) ((HtmlPage) win.getEnclosedPage())
.getDocumentElement().getOneHtmlElementByAttribute("table",
- "summary", tableSummaryOrId);
+ "summary", tableSummaryNameOrId);
} catch (ElementNotFoundException e) {
-
+ //Not found
}
+ try {
+ return (HtmlTable) ((HtmlPage) win.getEnclosedPage())
+ .getDocumentElement().getOneHtmlElementByAttribute("table",
+ "name", tableSummaryNameOrId);
+ } catch (ElementNotFoundException e) {
+ //Not found
+ }
return null;
}
- public boolean hasTable(String tableSummaryOrId) {
- HtmlTable table = getHtmlTable(tableSummaryOrId);
- return (table != null);
+ public boolean hasTable(String tableSummaryNameOrId) {
+ return getHtmlTable(tableSummaryNameOrId) != null;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <he...@us...> - 2012-11-27 16:00:36
|
Revision: 965
http://jwebunit.svn.sourceforge.net/jwebunit/?rev=965&view=rev
Author: henryju
Date: 2012-11-27 16:00:24 +0000 (Tue, 27 Nov 2012)
Log Message:
-----------
[3590256] Relax visibility of some methods in HtmlUnit plugin
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 2012-11-27 15:57:02 UTC (rev 964)
+++ trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2012-11-27 16:00:24 UTC (rev 965)
@@ -1120,7 +1120,7 @@
* response.
* @return HtmlForm object representing the current active form from the response.
*/
- private HtmlForm getForm() {
+ protected HtmlForm getForm() {
if (form == null) {
if (hasForm()) {
setWorkingForm(getForm(0));
@@ -1174,7 +1174,7 @@
return page.getForms();
}
- private HtmlPage getCurrentPage() {
+ protected HtmlPage getCurrentPage() {
Page page = win.getEnclosedPage();
if (page instanceof HtmlPage) {
return (HtmlPage) page;
@@ -2336,7 +2336,7 @@
/**
* @return Returns the testContext.
*/
- private TestContext getTestContext() {
+ protected TestContext getTestContext() {
return testContext;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|