The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

MikeHT (137) [Avatar] Offline
If you are using a recent version of Firefox, there are issues with running Selenium. There are solutions posted, but I couldn't get them to work. So I switched to using Chrome. You can switch to using other browsers by following a similar process to that below.
Note I'm running on a Mac, so if you are on a PC, some of the steps might be a bit different.

First, with later versions of Selenium, you must also have a driver for your browser, I download the at Put this somewhere on your hard drive. When you unzip this, you get a file named chromedriver (chromedriver.exe on Windows).

In the pom file, change




This will give you all the dependencies required to run not only FireFox, but Chrome, Opera, Safari and other browsers. In other words, <artifactId>selenium-java</artifactId> includes <artifactId>selenium-firefox-driver</artifactId> and the corresponding dependencies for other browsers. I also updated the versions of Selenium and Geb to the latest versions at the end of the pom file:


Then notice the project has a file src/test/resources/GebConfig.groovy. The book does not discuss this file, but it controls the browser that the test will run. I modified this file as shown below.

import org.openqa.selenium.firefox.FirefoxDriver

//driver = { new FirefoxDriver() }
driver = { new ChromeDriver() }

baseUrl = "http://localhost:9081"
reportsDir = "target/geb-reports"

Then open the run configuration for the test. Right click on the test file name (AddProductSpec.groovy) and select "Run As>Run Configurations" and on the Arguments tab, enter the following in the VM arguments box

This is the location of the chromedriver downloaded earlier.

Then run the project on a server and you should be able to run the test. I was then able to successfully run the test and launch Chrome. I got the following results.

Test 1

Condition not satisfied:

$(".col1").$("h2").text() == "New Product details"
| | | |
[] [] null false

at com.manning.spock.AddProductGebSpec.Navigation to page(AddProductGebSpec.groovy:24)

Test 2

Condition not satisfied:

$(".ok").text() == "You added new product named: Bravia TV."
| | |
[] null false

at com.manning.spock.AddProductGebSpec.Creation of new product(AddProductGebSpec.groovy:34)

Not yet sure why the tests are failing.

MikeHT (137) [Avatar] Offline
I figured out why the tests were failing. For some reason, in the second test, the Browser is launched with: {
			go "/web-ui-example/add-product.html"

This should be {
			go "http://localhost:8080/web-ui-example/add-product.html"

I'm not sure if I inadvertently removed the "http://localhost:8080" or it was in the source as downloaded, but the tests now pass.

Would love to know how to get this to run with Firefox, there seems to be a proxy issue I can't solve.
MikeHT (137) [Avatar] Offline
After looking more carefully into things, it was not necessary to make the above change to the URL in the test files. This is what the baseUrl variable in the GebConfig.groovy file is for. There are also other solutions for getting the chromedriver. You can add the following code to the test files:

	def setupSpec() {

Where "/Users/mht/Chromedriver/2.3.1/chromedriver" is the location where you downloaded the driver.

This solves the problem of where the driver is when you either run a test from a test file directly, or run with "mvn verify" from the command line.

If you don't add the above code to the the test files, to run from the command line, include the following on the command line:


If you want to run with a build configuration that has a goal of "verify", click on the project and select “Run As>Run Configurations>Maven Build" and create a new configuration. Give it a goal of "verify" and enter the above -DargLine into the VM argument list.

Be sure to change the baseUrl in GebConfig.groovy to that which has the port number matching the port number in the pom file. You can't use the argument when running this way as Maven arguments are not passed to the surefire and failsafe configurations, and both fork new JMVs which don’t get the arguments.
Kostis Kapelonis (63) [Avatar] Offline

Many thanks for these updated instructions! I am sure that a lot of readers will find them useful.

That is the problem with all technology books. Some instructions no longer apply or become obsolete when the book actually reaches your hands.