From 8005876da05b071c0b2aef2ec3a2c4939b2aeca6 Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Wed, 19 Dec 2012 18:12:36 +0000 Subject: [PATCH] TEST: use alternative UA to bypass UA spoofing. Small usage example of how PhantomJS Page Settings can be set via Capabilities. --- test/java/src/test/java/ghostdriver/BaseTest.java | 4 ++-- .../src/test/java/ghostdriver/NavigationTest.java | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/test/java/src/test/java/ghostdriver/BaseTest.java b/test/java/src/test/java/ghostdriver/BaseTest.java index dbc2df61f..465d91d55 100644 --- a/test/java/src/test/java/ghostdriver/BaseTest.java +++ b/test/java/src/test/java/ghostdriver/BaseTest.java @@ -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 { diff --git a/test/java/src/test/java/ghostdriver/NavigationTest.java b/test/java/src/test/java/ghostdriver/NavigationTest.java index aad6754c5..29f809505 100644 --- a/test/java/src/test/java/ghostdriver/NavigationTest.java +++ b/test/java/src/test/java/ghostdriver/NavigationTest.java @@ -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; @@ -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(); @@ -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/"); }