Skip to content

Commit

Permalink
JimEvans: Adding a target for running the standard WebDriver test sui…
Browse files Browse the repository at this point in the history
…te against PhantomJS. To run it, you'll need PhantomJS (with the GhostDriver bits included) on the system. The CrazyFun target is ./go //java/client/test/org/openqa/selenium/phantomjs:test:run

r18294
  • Loading branch information
jimevans committed Dec 11, 2012
1 parent eaa30a5 commit 503ab59
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions java/client/src/org/openqa/selenium/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ java_library(name = "client-combined",
"//java/client/src/org/openqa/selenium/support",
"//java/client/src/org/openqa/selenium:webdriver-backed-selenium",
"//third_party/java/opera-driver",
"//third_party/java/phantomjs-driver",
])

java_library(name = "codecs",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2012 Selenium committers
Copyright 2012 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/


package org.openqa.selenium.phantomjs;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.openqa.selenium.StandardSeleniumTests;

@RunWith(Suite.class)
@Suite.SuiteClasses({
StandardSeleniumTests.class
})
public class PhantomJSDriverTests {
}
13 changes: 13 additions & 0 deletions java/client/test/org/openqa/selenium/phantomjs/build.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
java_test(name = "test",
srcs = [
"*.java",
],
sysproperties = [
{ "selenium.browser" : "phantomjs" },
],
deps = [
"//java/client/test/org/openqa/selenium:tests",
"//third_party/java/junit",
"//third_party/java/phantomjs-driver"
]
)
1 change: 1 addition & 0 deletions java/client/test/org/openqa/selenium/testing/Ignore.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static enum Driver {
IPHONE,
OPERA,
OPERA_MOBILE,
PHANTOMJS,
REMOTE,
SAFARI,
SELENESE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public boolean isJavascriptEnabled() {
none, // For those cases where you don't actually want a browser
opera,
opera_mobile,
phantomjs,
safari;

private static final Logger log = Logger.getLogger(Browser.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public static DesiredCapabilities of(Browser browser) {
caps.setCapability(OperaSettings.Capability.PRODUCT.getCapability(), OperaProduct.MOBILE);
break;

case phantomjs:
caps = DesiredCapabilities.phantomjs();
break;

case safari:
caps = DesiredCapabilities.safari();
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2012 Selenium committers
Copyright 2012 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.openqa.selenium.testing.drivers;

import com.google.common.base.Supplier;

import org.openqa.selenium.phantomjs.PhantomJSDriver;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class PhantomJSDriverSupplier implements Supplier<WebDriver> {

private final Capabilities capabilities;

public PhantomJSDriverSupplier(Capabilities capabilities) {
this.capabilities = capabilities;
}

public WebDriver get() {
if (capabilities == null) {
return null;
}

if (!DesiredCapabilities.phantomjs().getBrowserName().equals(capabilities.getBrowserName())) {
return null;
}

// It's okay to avoid reflection here because the OperaDriver is a third party dependency
return new PhantomJSDriver(capabilities);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.openqa.selenium.testing.Ignore.Driver.IPHONE;
import static org.openqa.selenium.testing.Ignore.Driver.OPERA;
import static org.openqa.selenium.testing.Ignore.Driver.OPERA_MOBILE;
import static org.openqa.selenium.testing.Ignore.Driver.PHANTOMJS;
import static org.openqa.selenium.testing.Ignore.Driver.REMOTE;
import static org.openqa.selenium.testing.Ignore.Driver.SAFARI;
import static org.openqa.selenium.testing.Ignore.Driver.SELENESE;
Expand All @@ -55,6 +56,7 @@
import static org.openqa.selenium.testing.drivers.Browser.ipad;
import static org.openqa.selenium.testing.drivers.Browser.iphone;
import static org.openqa.selenium.testing.drivers.Browser.opera;
import static org.openqa.selenium.testing.drivers.Browser.phantomjs;

/**
* Class that decides whether a test class or method should be ignored.
Expand Down Expand Up @@ -209,6 +211,10 @@ private void addIgnoresForBrowser(Browser browser, IgnoreComparator comparator)
comparator.addDriver(REMOTE);
break;

case phantomjs:
comparator.addDriver(PHANTOMJS);
break;

case safari:
comparator.addDriver(SAFARI);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private List<Supplier<WebDriver>> getSuppliers(Capabilities desiredCaps,
suppliers.add(new RemoteSupplier(desiredCaps, requiredCaps));
suppliers.add(new SeleniumBackedSupplier(desiredCaps));
suppliers.add(new OperaDriverSupplier(desiredCaps));
suppliers.add(new PhantomJSDriverSupplier(desiredCaps));
suppliers.add(new TestInternetExplorerSupplier(desiredCaps));
suppliers.add(new ReflectionBackedDriverSupplier(desiredCaps, requiredCaps));
suppliers.add(new DefaultDriverSupplier(desiredCaps, requiredCaps));
Expand Down

0 comments on commit 503ab59

Please sign in to comment.