Geb-未使用ChromeOptions

时间:2018-10-11 17:38:20

标签: selenium-chromedriver geb chrome-options

Geb test ignoring GebConfig.groovy file launched in IntelliJ帮助我使用了ChromeDriver,但是现在我遇到的问题是,尽管提供了ChromeOptions,但仍未使用。

我采用了提供的解决方案,只是添加了其他StackOverflow解决方案中的分配:

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)
      }
    }
}

现在浏览器运行良好,但是未使用opts:未最大化,浏览器的外观显然不正确。当我使用纯硒时,我遇到了同样的问题,我通过使用上面的user-data-dir解决了这个问题。也使用相同的ChromeDriver。

程序输出显示:

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

尝试(不建议使用)DesiredCapabilities,但相同。

TIA

2 个答案:

答案 0 :(得分:0)

这是一件小事,但是the docs show为ChromeOptions提供了不带“-”前缀的args。

ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");

答案 1 :(得分:0)

我认为您的问题是:

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

我不认为此操作应该在GebConfig.groovy文件中进行。那可能是导致您的问题的原因。我不确定100%。其他一切对我来说看起来都很好(每个命令之前的“-”除外),而且我之前已经成功使用了chrome选项,而我看到的设置和您的设置之间的唯一区别就是该行

System.setProperty("webdriver.chrome.driver", "my/path")
对我来说,

在我的build.gradle文件中,而不在GebConfig.groovy文件中。尝试将其移至构建脚本中,看看会发生什么情况

相关问题