0

Geb test ignoring GebConfig.groovy file launched in IntelliJ helped me get the ChromeDriver to be used, but now I have the problem that ChromeOptions are not being used despite being supplied.

I took the solution provided and just added the assignments found in other StackOverflow solutions:

import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions

System.setProperty("webdriver.chrome.driver", "my/path")


// This was one option suggested, but I'm trying the assignment inside the environment block.
// I tried this way, too.
//    driver = {new ChromeDriver()}


environments {
    chrome {
       driver = {
           ChromeOptions opts = new ChromeOptions()
           opts.addArguments("--user-data-dir=/home/guy/.config/automation-google-chrome/")
           opts.addArguments("--start-maximized")
           new ChromeDriver(opts)
      }
    }
}

Now the browser comes up fine, but the opts are not used: not maximized, and the browser look-and-feel is obviously not right. I had the same problem when I was using straight Selenium, and I solved it by using the user-data-dir above. Using same ChromeDriver, too.

The program output says:

Starting ChromeDriver 2.20.353124 (very long number here) on port 25082

Tried (deprecated) DesiredCapabilities, but same.

TIA

Guy
  • 666
  • 1
  • 10
  • 34
  • Are you sure that you are running in `chrome` geb environment so that the `driver` closure that sets up `ChromeOption` is actually executed? You could verify that by throwing an exception from within that closure and seeing your test failing to start up. – erdi Oct 21 '18 at 14:12

2 Answers2

0

It's a small thing, but the docs show providing args to ChromeOptions without the "--" prefix.

ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
Doug Clark
  • 332
  • 5
  • 21
0

I think your issue is:

System.setProperty("webdriver.chrome.driver", "my/path")

I don't believe that this operation is supposed to take place in the GebConfig.groovy file. And that maybe what is causing your problems. I am not 100% sure though. Everything else looks fine to me (except the "--" before each command), and I have used chrome options successfully before, and the only difference I see between my setup and yours is that this line

System.setProperty("webdriver.chrome.driver", "my/path")

for me is inside of my build.gradle file, and not inside of the GebConfig.groovy file. Try moving it into your build script and see what happens

switch201
  • 587
  • 1
  • 4
  • 16
  • I need to take a few Gradle tutorials, I think. I set the property in the `build.gradle` file, but not using the same line verbatim. I did test { systemProperties "webdriver.chrome.driver": "/home/myname/chromedriver" } So your suggestion to move the property assignment to the build file did indeed work, but now I need to figure out how to set the options there as well. – Guy Oct 21 '18 at 14:35
  • @Guy I don't think you should have to set the options in the build.gradle. I know for my projects I still set all my options in the `GebConfig.groovy` while I set my system variables in my `build.gradle`. Sorry I am not an expert on this, I just have used chrome options before and this is how I got it to work. the only difference between my script and yours was the system property thing. other than that you shouldn't have to chnage anything. – switch201 Oct 22 '18 at 15:09