0
votes

I'm trying to work through this example from the Maven cookbook to run a Selenium Test:

https://books.sonatype.com/mcookbook/reference/ch08s02.html

I have created the project as specified, and the TwitterTest.java class.

The only changes I made were to change the port Selenium runs on to 7777. I did this by changing the code:

    this.selenium = new DefaultSelenium("localhost", 7777, "*safari",  "http://www.twitter.com");

and in the POM I added:

<properties>
    <selenium.server.port>7777</selenium.server.port>
</properties>

and modified:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>selenium-maven-plugin</artifactId>
            <configuration>
                <port>${selenium.server.port}</port>
            </configuration>
     ...

I did this because Server.app runs launchd on port 4444.

When I run mvn integration-test, I get the following output:

[INFO] --- selenium-maven-plugin:2.3:start-server (default) @ crm-test ---

Launching Selenium Server

Waiting for Selenium Server...

[INFO] User extensions: /Users/george/workspace/crm-test/target/selenium/user-extensions.js

17:22:12,724 INFO [org.openqa.selenium.server.SeleniumServer] Java: Oracle Corporation 25.102-b14

17:22:12,725 INFO [org.openqa.selenium.server.SeleniumServer] OS: Mac OS X 10.12.6 x86_64

17:22:12,732 INFO [org.openqa.selenium.server.SeleniumServer] v2.21.0, with Core v2.21.0. Built from revision 16551

17:22:12,841 INFO [org.openqa.selenium.server.SeleniumServer] RemoteWebDriver instances should connect to: http://127.0.0.1:7777/wd/hub

17:22:12,842 INFO [org.openqa.jetty.http.HttpServer] Version Jetty/5.1.x

17:22:12,843 INFO [org.openqa.jetty.util.Container] Started HttpContext[/selenium-server,/selenium-server]

17:22:12,867 INFO [org.openqa.jetty.util.Container] Started org.openqa.jetty.jetty.servlet.ServletHandler@61a485d2

17:22:12,867 INFO [org.openqa.jetty.util.Container] Started HttpContext[/wd,/wd]

17:22:12,867 INFO [org.openqa.jetty.util.Container] Started HttpContext[/selenium-server/driver,/selenium-server/driver]

17:22:12,867 INFO [org.openqa.jetty.util.Container] Started HttpContext[/,/]

17:22:12,873 INFO [org.openqa.jetty.http.SocketListener] Started SocketListener on 0.0.0.0:7777

17:22:12,873 INFO [org.openqa.jetty.util.Container] Started org.openqa.jetty.jetty.Server@65ae6ba4

17:22:13.325 INFO - Checking Resource aliases

Selenium Server started

[INFO]

[INFO] --- maven-surefire-plugin:2.12.4:test (default) @ crm-test ---

[INFO] Surefire report directory: /Users/george/workspace/crm-test/target/surefire-reports


T E S T S


Running org.sonatype.mcookbook.TwitterTest

Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@66cd51c3

17:22:14,365 INFO [org.openqa.jetty.util.Credential] Checking Resource aliases

17:22:14.369 INFO - Command request: getNewBrowserSession[*safari, http://www.twitter.com, ] on session null

17:22:14.372 INFO - creating new remote session

17:22:14.404 INFO - Allocated session 1acfb5c8359144f5aba4922bc8406c0c for http://www.twitter.com, launching...

17:22:14.458 INFO - Launching Safari to visit 'file:/var/folders/02/t683l6k918v1s_sr0y8k71zm0000gn/T/customProfileDir1acfb5c8359144f5aba4922bc8406c0c/core/RemoteRunner.html?sessionId=1acfb5c8359144f5aba4922bc8406c0c&multiWindow=true&baseUrl=http%3A%2F%2Fwww.twitter.com&debugMode=false&driverUrl=http://localhost:7777/selenium-server/driver/' via '/var/folders/02/t683l6k918v1s_sr0y8k71zm0000gn/T/customProfileDir1acfb5c8359144f5aba4922bc8406c0c/redirect_to_go_to_selenium.htm'...

A Safari window opens, displaying the Selenium console (Selenium Functional Testing for Web Apps, Open Source From ThoughtWorks and Friends)

But other than that, the console just sits there, at 'Launching Safari to visit' indefinitely with no further progress.

I'm not sure if this is a java-related problem, or something environmental. If it helps, I'm running a Mac Pro Server with Sierra (10.12.6)

Update: after several minutes it outputs:

17:52:23.843 ERROR - Failed to start new browser session, shutdown browser and clear all session data org.openqa.selenium.server.RemoteCommandException: timed out waiting for window 'null' to appear

If I look in the Developer Console, I see the following messages:

[Error] Not allowed to load local resource: file:///var/folders/02/t683l6k918v1s_sr0y8k71zm0000gn/T/customProfileDird2e9a9287f5648fc921212a0230f2eb5/core/scripts/user-extensions.js[d2e9a9287f5648fc921212a0230f2eb5] requireExtensionJs (selenium-remoterunner.js:581) getSessionId (selenium-remoterunner.js:65) buildDriverParams (selenium-remoterunner.js:464) addUrlParams (selenium-remoterunner.js:415) sendToRC (selenium-remoterunner.js:399) nextCommand (selenium-remoterunner.js:203) continueTest (selenium-executionloop.js:35) start (selenium-executionloop.js:26) runSeleniumTest (selenium-remoterunner.js:125) (anonymous function) (RemoteRunner.html:58)

[Error] Origin null is not allowed by Access-Control-Allow-Origin.

[Error] Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. (driver, line 0)

[Error] XMLHttpRequest cannot load http://localhost:7777/selenium-server/driver/?seleniumStart=true&localFrameAddress=top&seleniumWindowName=&uniqueId=sel_94166&sessionId=d2e9a9287f5648fc921212a0230f2eb5&counterToMakeURsUniqueAndSoStopPageCachingInTheBrowser=1530146840266&sequenceNumber=0 due to access control checks.

Is there a way to circumvent these?

Notes: - if I try using use *firefox or *chrome I get:

18:01:17.623 INFO - Preparing Firefox profile... 18:01:39.160 ERROR - Failed to start new browser session, shutdown browser and clear all session data java.lang.RuntimeException: Timed out waiting for profile to be created!

Note the message says Preparing Firefox profile whether I try to use *firefox OR *chrome

1
@user8035311 updated question with results of using *firefox instead - Black
if you mean the process it goes through automatically the first time you open Firefox that has been done. I'm able to use Firefox as a normal browser. Are you referring to some other Selenium-specific set up? - Black
I just tried manually creating a new Firefox profile, but it hasn't changed the results of these tests - Black
mvn integration-test as it says above - Black

1 Answers

0
votes

Wow, I have returned from the rabbit-hole. In order to get my Selenium tests to run on Mac OSX, I had to do the following:

  1. use the *googlechrome driver
  2. Install the Java Cryptography Extension into my JRE/JDK: http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
  3. pass the following property value to maven : mvn integration-test -Dmaven.wagon.http.ssl.insecure=true
  4. add the following configuration to selenium-maven-plugin:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>selenium-maven-plugin</artifactId>
            <configuration>
                <trustAllSSLCertificates>true</trustAllSSLCertificates>
                ...