Skip to content

Commit 68ba3f6

Browse files
committedOct 9, 2007
SimonStewart: Moving to Java 5. Firefox driver will now find the binary by looking at the 'firefox.bin' system property
r4357
1 parent d9947bf commit 68ba3f6

File tree

20 files changed

+157
-76
lines changed

20 files changed

+157
-76
lines changed
 

‎Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def javac(args)
149149
mkdir_p target_dir, :verbose => false
150150

151151
compile_string = "javac "
152-
compile_string += "-source 1.4 -target 1.4 "
152+
compile_string += "-source 5 -target 5 "
153153
compile_string += "-g " if debug
154154
compile_string += "-d #{target_dir} "
155155

‎WebDriver.ipr

+18-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
<component name="AntConfiguration">
44
<defaultAnt bundledAnt="true" />
55
</component>
6+
<component name="Build editor project-level loader">
7+
<settings>
8+
<class-settings class="com.google.devtools.intellig.configcheck.ClearOutputChecker" />
9+
<class-settings class="com.google.devtools.intellig.configcheck.JavacHeapChecker" />
10+
<class-settings class="com.google.devtools.intellig.configcheck.ProjectJdkChecker" />
11+
<class-settings class="com.google.devtools.intellig.configcheck.ProjectPathChecker" />
12+
<class-settings class="com.google.devtools.intellig.configcheck.PythonSdkChecker" />
13+
</settings>
14+
</component>
615
<component name="BuildJarProjectSettings">
716
<option name="BUILD_JARS_ON_MAKE" value="false" />
817
</component>
@@ -638,7 +647,7 @@
638647
<option name="GENERATE_NO_WARNINGS" value="false" />
639648
<option name="DEPRECATION" value="true" />
640649
<option name="ADDITIONAL_OPTIONS_STRING" value="" />
641-
<option name="MAXIMUM_HEAP_SIZE" value="128" />
650+
<option name="MAXIMUM_HEAP_SIZE" value="800" />
642651
</component>
643652
<component name="JavadocGenerationManager">
644653
<option name="OUTPUT_DIRECTORY" />
@@ -671,6 +680,13 @@
671680
<option name="FILTER_INFO" value="true" />
672681
<option name="CUSTOM_FILTER" />
673682
</component>
683+
<component name="Mach integration configuration">
684+
<pre-compile target="" enabled="false" />
685+
<use-mach-for-java enabled="false" />
686+
<mach-version />
687+
<working-set enabled="false" />
688+
<previous-paths />
689+
</component>
674690
<component name="Palette2">
675691
<group name="Swing">
676692
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
@@ -801,7 +817,7 @@
801817
<module fileurl="file://$PROJECT_DIR$/selenium/selenium.iml" filepath="$PROJECT_DIR$/selenium/selenium.iml" />
802818
</modules>
803819
</component>
804-
<component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="false" project-jdk-name="1.5" project-jdk-type="JavaSDK">
820+
<component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="1.5" project-jdk-type="JavaSDK">
805821
<output url="file://$PROJECT_DIR$/build/eclipse" />
806822
</component>
807823
<component name="ProjectRunConfigurationManager" />
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#Tue Jan 02 12:40:47 GMT 2007
1+
#Mon Oct 08 16:13:48 BST 2007
22
eclipse.preferences.version=1
3+
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
34
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
5+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
56
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6-
org.eclipse.jdt.core.compiler.compliance=1.4
7+
org.eclipse.jdt.core.compiler.compliance=1.5
78
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
89
org.eclipse.jdt.core.compiler.debug.localVariable=generate
910
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10-
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
11-
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
12-
org.eclipse.jdt.core.compiler.source=1.3
11+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13+
org.eclipse.jdt.core.compiler.source=1.5
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#Tue Jan 02 12:40:47 GMT 2007
1+
#Mon Oct 08 16:13:49 BST 2007
22
eclipse.preferences.version=1
3-
internal.default.compliance=default
3+
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true

‎common/src/java/com/thoughtworks/webdriver/WebDriver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public interface WebDriver {
117117
* @return A list of all {@link WebElement}s matching the XPath, or an
118118
* empty list if nothing matches
119119
*/
120-
List selectElements(String xpath);
120+
List<WebElement> selectElements(String xpath);
121121

122122
/**
123123
* Select the first {@link WebElement} which matches the given selector. The
@@ -172,7 +172,7 @@ public interface TargetLocator {
172172
* the second at index "1" and the third at index "2". Once the frame has been selected, all subsequent calls on the WebDriver interface are made to that frame.
173173
*
174174
* @param frameIndex
175-
* @return
175+
* @return A driver focused on the given frame
176176
*/
177177
WebDriver frame(int frameIndex);
178178

‎common/src/java/com/thoughtworks/webdriver/WebElement.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public interface WebElement {
127127
* @param tagName The tag name of the child elements.
128128
* @return A list of {@link WebElement}s of the given type.
129129
*/
130-
List getChildrenOfType(String tagName);
130+
List<WebElement> getChildrenOfType(String tagName);
131131

132132
/**
133133
* Is this element displayed or not? Typically, this will make the most sense on full
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Mon Oct 08 16:14:03 BST 2007
2+
eclipse.preferences.version=1
3+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.5
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.source=1.5

‎firefox/src/java/com/thoughtworks/webdriver/firefox/FirefoxDriver.java

+36-7
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ public WebElement selectElement(String selector) {
9393
return new FirefoxWebElement(this, elementId);
9494
}
9595

96-
public List selectElements(String xpath) {
96+
public List<WebElement> selectElements(String xpath) {
9797
String returnedIds = sendMessage("selectElementsUsingXPath", xpath);
9898
String[] ids = returnedIds.split(",");
99-
List elements = new ArrayList();
99+
List<WebElement> elements = new ArrayList<WebElement>();
100100
for (int i = 0; i < ids.length; i++) {
101101
elements.add(new FirefoxWebElement(this, ids[i]));
102102
}
@@ -119,16 +119,19 @@ public TargetLocator switchTo() {
119119
}
120120

121121
private File locateFirefoxBinary() {
122+
File potentialPath = locateFirefoxBinaryFromSystemProperty();
123+
if (potentialPath != null || potentialPath.exists())
124+
return potentialPath;
125+
122126
String osName = System.getProperty("os.name").toLowerCase();
123-
File potentialPath;
124127
if (osName.startsWith("windows")) {
125128
potentialPath = new File(
126129
"\\Program Files\\Mozilla Firefox\\firefox.exe");
127130
} else if (osName.startsWith("mac")) {
128131
potentialPath = new File(
129132
"/Applications/Firefox.app/Contents/MacOS/firefox");
130133
} else {
131-
potentialPath = shellOutAndFindPathOfFirefox();
134+
potentialPath = shellOutAndFindPathOfFirefox("firefox");
132135
}
133136

134137
if (potentialPath.exists())
@@ -137,10 +140,35 @@ private File locateFirefoxBinary() {
137140
"Unable to locate location of firefox binary");
138141
}
139142

140-
private File shellOutAndFindPathOfFirefox() {
143+
private File locateFirefoxBinaryFromSystemProperty() {
144+
String binaryName = System.getProperty("firefox.bin");
145+
if (binaryName == null)
146+
return null;
147+
148+
File binary = new File(binaryName);
149+
if (binary.exists())
150+
return binary;
151+
152+
String osName = System.getProperty("os.name").toLowerCase();
153+
if (osName.contains("windows"))
154+
return null; // Who knows how to handle this
155+
156+
if (osName.contains("mac")) {
157+
if (!binaryName.endsWith(".app"))
158+
binaryName += ".app";
159+
binaryName += "/Contents/MacOS/firefox";
160+
return new File(binaryName);
161+
}
162+
163+
// Assume that we're on a UNIX variant
164+
return shellOutAndFindPathOfFirefox(binaryName);
165+
166+
}
167+
168+
private File shellOutAndFindPathOfFirefox(String binaryName) {
141169
// Assume that we're on a unix of some kind. We're going to cheat
142170
try {
143-
Process which = Runtime.getRuntime().exec("which firefox");
171+
Process which = Runtime.getRuntime().exec(new String[] {"which", binaryName});
144172
BufferedReader reader = new BufferedReader(new InputStreamReader(
145173
which.getInputStream()));
146174
return new File(reader.readLine());
@@ -152,9 +180,10 @@ private File shellOutAndFindPathOfFirefox() {
152180
private void startFirefox(File firefoxBinary) {
153181
File binary = firefoxBinary;
154182

155-
if (firefoxBinary == null)
183+
if (firefoxBinary == null) {
156184
binary = locateFirefoxBinary();
157185

186+
}
158187
try {
159188
if (!binary.exists()) {
160189
throw new RuntimeException("Unable to locate firefox binary. Please check that it is installed in the default location, " +

‎firefox/src/java/com/thoughtworks/webdriver/firefox/FirefoxWebElement.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ public String getText() {
9090
return parent.sendMessage("getElementText", elementId);
9191
}
9292

93-
public List getChildrenOfType(String tagName) {
93+
public List<WebElement> getChildrenOfType(String tagName) {
9494
String response = parent.sendMessage("getElementChildren", elementId + " " + tagName);
9595
String[] ids = response.split(" ");
9696

97-
ArrayList children = new ArrayList();
97+
ArrayList<WebElement> children = new ArrayList<WebElement>();
9898
for (int i = 0; i < ids.length; i++)
9999
children.add(new FirefoxWebElement(parent, ids[i]));
100100

‎firefox/test/java/com/thoughtworks/webdriver/firefox/FirefoxDriverTest.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
import com.thoughtworks.webdriver.WebDriver;
66

77
import java.io.File;
8+
import java.io.BufferedReader;
9+
import java.io.InputStreamReader;
10+
import java.io.IOException;
811

912
public class FirefoxDriverTest extends JavascriptEnabledDriverTest {
1013
protected WebDriver getDriver() {
11-
String firefoxBinary = System.getProperty("firefox.bin");
12-
File binary = null;
13-
if (firefoxBinary != null) {
14-
System.out.println("Using: " + firefoxBinary);
15-
binary = new File(firefoxBinary);
16-
}
17-
return new FirefoxDriver(binary);
14+
return new FirefoxDriver();
1815
}
1916

2017
protected boolean isUsingSameDriverInstance() {
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#Tue Jan 02 13:01:15 GMT 2007
1+
#Mon Oct 08 16:14:11 BST 2007
22
eclipse.preferences.version=1
3+
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
34
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
5+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
56
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6-
org.eclipse.jdt.core.compiler.compliance=1.4
7+
org.eclipse.jdt.core.compiler.compliance=1.5
78
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
89
org.eclipse.jdt.core.compiler.debug.localVariable=generate
910
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10-
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
11-
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
12-
org.eclipse.jdt.core.compiler.source=1.3
11+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13+
org.eclipse.jdt.core.compiler.source=1.5
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#Tue Jan 02 13:01:15 GMT 2007
1+
#Mon Oct 08 16:14:11 BST 2007
22
eclipse.preferences.version=1
3-
internal.default.compliance=default
3+
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true

‎htmlunit/src/java/com/thoughtworks/webdriver/htmlunit/HtmlUnitDriver.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,15 @@ public String selectText(String selector) {
119119
return element.getText();
120120
}
121121

122-
public List selectElements(String selector) {
122+
@SuppressWarnings("unchecked")
123+
public List<WebElement> selectElements(String selector) {
123124
try {
124125
HtmlUnitXPath xpath = new HtmlUnitXPath(selector);
125-
List nodes = xpath.selectNodes(lastPage());
126-
List elements = new ArrayList();
126+
List<HtmlElement> nodes = xpath.selectNodes(lastPage());
127+
List<WebElement> elements = new ArrayList<WebElement>();
127128

128129
for (int i = 0; i < nodes.size(); i++) {
129-
elements.add(new HtmlUnitWebElement(this, (HtmlElement) nodes.get(i)));
130+
elements.add(new HtmlUnitWebElement(this, nodes.get(i)));
130131
}
131132

132133
return elements;
@@ -164,14 +165,15 @@ private synchronized HtmlPage lastPage() {
164165
return (HtmlPage) currentWindow.getEnclosedPage();
165166
}
166167

168+
@SuppressWarnings("unchecked")
167169
private WebElement selectLinkWithText(String selector) {
168170
int equalsIndex = selector.indexOf('=') + 1;
169171
String expectedText = selector.substring(equalsIndex).trim();
170172

171-
List anchors = lastPage().getAnchors();
172-
Iterator allAnchors = anchors.iterator();
173+
List<HtmlAnchor> anchors = lastPage().getAnchors();
174+
Iterator<HtmlAnchor> allAnchors = anchors.iterator();
173175
while (allAnchors.hasNext()) {
174-
HtmlAnchor anchor = (HtmlAnchor) allAnchors.next();
176+
HtmlAnchor anchor = allAnchors.next();
175177
if (expectedText.equals(anchor.asText())) {
176178
return new HtmlUnitWebElement(this, anchor);
177179
}
@@ -211,7 +213,7 @@ public WebDriver frame(int frameIndex) {
211213
}
212214

213215
public WebDriver window(String windowId) {
214-
WebWindow window = (WebWindow) webClient.getWebWindowByName(windowId);
216+
WebWindow window = webClient.getWebWindowByName(windowId);
215217
webClient.setCurrentWindow(window);
216218
pickWindow();
217219
return HtmlUnitDriver.this;

‎htmlunit/src/java/com/thoughtworks/webdriver/htmlunit/HtmlUnitWebElement.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,15 @@ private boolean isWhiteSpace(int lastChar) {
201201
return lastChar == '\n' || lastChar == ' ' || lastChar == '\t' || lastChar == '\r';
202202
}
203203

204+
@SuppressWarnings("unchecked")
204205
private void getTextFromNode(DomNode node, StringBuffer toReturn, StringBuffer textSoFar, boolean isPreformatted) {
205206
if (isPreformatted) {
206207
getPreformattedText(node, toReturn);
207208
}
208209

209-
Iterator children = node.getChildIterator();
210+
Iterator<DomNode> children = node.getChildIterator();
210211
while (children.hasNext()) {
211-
DomNode child = (DomNode) children.next();
212+
DomNode child = children.next();
212213

213214
// Do we need to collapse the text so far?
214215
if (child instanceof HtmlPreformattedText) {
@@ -264,11 +265,12 @@ private void getPreformattedText(DomNode node, StringBuffer toReturn) {
264265
toReturn.append(xmlText.replaceAll("^<pre.*?>", "").replaceAll("</pre.*>$", ""));
265266
}
266267

267-
public List getChildrenOfType(String tagName) {
268-
Iterator allChildren = element.getAllHtmlChildElements();
269-
List elements = new ArrayList();
268+
@SuppressWarnings("unchecked")
269+
public List<WebElement> getChildrenOfType(String tagName) {
270+
Iterator<HtmlElement> allChildren = element.getAllHtmlChildElements();
271+
List<WebElement> elements = new ArrayList<WebElement>();
270272
while (allChildren.hasNext()) {
271-
HtmlElement child = (HtmlElement) allChildren.next();
273+
HtmlElement child = allChildren.next();
272274
if (tagName.equals(child.getTagName())) {
273275
elements.add(new HtmlUnitWebElement(parent, child));
274276
}
+13-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#Wed Jan 03 19:52:42 GMT 2007
2-
eclipse.preferences.version=1
3-
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
5-
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6-
org.eclipse.jdt.core.compiler.compliance=1.4
7-
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8-
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9-
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10-
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
11-
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
12-
org.eclipse.jdt.core.compiler.source=1.3
1+
#Mon Oct 08 16:14:19 BST 2007
2+
eclipse.preferences.version=1
3+
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
4+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
5+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
6+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
7+
org.eclipse.jdt.core.compiler.compliance=1.5
8+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
9+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
10+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
11+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13+
org.eclipse.jdt.core.compiler.source=1.5
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#Tue Jan 02 13:01:27 GMT 2007
1+
#Mon Oct 08 16:14:20 BST 2007
22
eclipse.preferences.version=1
3-
internal.default.compliance=default
3+
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true

‎jobbie/src/java/com/thoughtworks/webdriver/ie/ElementNode.java

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
public class ElementNode implements HtmlNode {
5+
@SuppressWarnings("unused")
56
private final long nodePointer;
67

78
public ElementNode(long nodePointer) {

0 commit comments

Comments
 (0)