Skip to content

Commit

Permalink
TEST: use alternative UA to bypass UA spoofing.
Browse files Browse the repository at this point in the history
Small usage example of how PhantomJS Page Settings can be set via Capabilities.
  • Loading branch information
detro committed Dec 19, 2012
1 parent d3b74f6 commit 8005876
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/java/src/test/java/ghostdriver/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public abstract class BaseTest {
private static final String DRIVER_FIREFOX = "firefox";
private static final String DRIVER_PHANTOMJS = "phantomjs";

private static Properties sConfig;
private static DesiredCapabilities sCaps;
protected static Properties sConfig;
protected static DesiredCapabilities sCaps;

private static boolean isUrl(String urlString) {
try {
Expand Down
15 changes: 13 additions & 2 deletions test/java/src/test/java/ghostdriver/NavigationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@

package ghostdriver;

import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

Expand All @@ -39,6 +41,15 @@
import static org.junit.Assert.assertTrue;

public class NavigationTest extends BaseTest {
@BeforeClass
public static void setUserAgentForPhantomJSDriver() {
// Setting a generic Chrome UA to bypass some UA spoofing
sCaps.setCapability(
PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "userAgent",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
);
}

@Test
public void navigateAroundMDN() {
WebDriver d = getDriver();
Expand Down Expand Up @@ -77,8 +88,8 @@ public void navigateToGoogleAdwords() {

@Test
public void navigateToNameJet() {
// NOTE: This test is supposed to fail, because the UA of PhantomJS is rejected.
// We need this implemented: https://github.com/detro/ghostdriver/issues/131
// NOTE: This passes only when the User Agent is NOT PhantomJS {@see setUserAgentForPhantomJSDriver}
// method above.
WebDriver d = getDriver();
d.navigate().to("http://www.namejet.com/");
}
Expand Down

0 comments on commit 8005876

Please sign in to comment.