GOCD管道,未设置Selenium ChromeDriver窗口大小 [英] GOCD pipeline, Selenium ChromeDriver window size is not set

查看:90
本文介绍了GOCD管道,未设置Selenium ChromeDriver窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

ChromeOptions.addArguments("--start-maximized");

driver.manage().window().setSize(new Dimension(1980,1080));

ChromeOptions.addArguments("window-size=1980,1080");

ChromeOptions.addArguments("--window-size=1980,1080");

Chrome窗口设置为正确的大小,并且在从终端运行测试或从intellij运行单个测试用例(所有测试均通过)时完美运行

the Chrome window is set to the correct size and works perfectly when running the tests from either the terminal or running individual test cases from intellij (all tests Pass)

但是,当我的GOCD管道开始工作时,一切都开始工作(测试开始正常执行),然后在日志中看到测试中使用的窗口大小为1044 x 788.

However, when my GOCD pipeline picks up the job, everything starts working (tests start executing normally) then in the log I see that the window being used in the test has a size of 1044 x 788.

这会导致问题,因为由于屏幕的大小(我认为),我需要的按钮位于最右边且不在视野范围内

This causes an issue as a button I need is on the far right and out of the field of view due to the size of the screen (I assume)

收到的消息是

    2018-11-28 13:38:52.542  WARN 4456 --- [           main] utils.PageUtils                          : element not interactable
  (Session info: chrome=70.0.3538.110)
  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:25:02.294Z'
System info: host: 'DEV', ip: '192.168.1.177', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.44.609538 (b655c5a60b0b54..., userDataDir: C:\windows\TEMP\scoped_dir1...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:62401}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 70.0.3538.110, webStorageEnabled: true}
Session ID: e3f442486d9087e190e0954c5fcc19f5: Click(btnSearchDropMenu) failed! re trying...
2018-11-28 13:38:52.549  WARN 4456 --- [           main] utils.PageUtils                          : Screen dimentions: (1044, 788)
2018-11-28 13:38:52.550  INFO 4456 --- [           main] utils.PageUtils                          : Scrolling to move 'btnSearchDropMenu' to the middle of the screen
2018-11-28 13:38:53.619 ERROR 4456 --- [           main] BaseTestFolder.BaseTest                  : org.openqa.selenium.ElementNotVisibleException: element not interactable
  (Session info: chrome=70.0.3538.110)
  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds

我尝试过在不同区域传递set size命令,包括在尝试单击缺少的按钮之前,以及在将选项传递给chrome选项对象之前,将选项重新传递给chrome驱动程序之前,将其重新排序.

I have tried passing the set size command in different areas including just before trying to click the button that's missing and re ordered when options are passed to my chrome options object before they are passed to the chrome driver.

我需要窗口至少为1980x1080,但是我不确定为什么在GOCD上运行测试时无法设置该值

I need the window to be at least 1980x1080 but i'm unsure why this is not able to be set when the tests run on the GOCD

我不知道为什么会发生此问题.任何帮助将不胜感激

I'm at a loss as to why this issue is occurring. any help would be greatly appreciated

**编辑1 **

奇怪的是,我可以减小窗口大小,并且此属性将保持不变...

What is strange is that I can reduce the window size and this property will keep...

2018-11-28 15:47:02.754  INFO 19088 --- [           main] configuration.GoogleChrome               : Window size: (1000, 600)

编辑2

添加了我尝试过的另一个参数

Added another argument i tried,

这也是jenkins的问题-默认设置为相同的窗口大小:(1044,788)

This is also an issue with jenkins- defaults to the same Window size: (1044, 788)

推荐答案

此问题似乎是由两个问题引起的,

This issue looks to have been caused by two issues,

1-从IDE运行mvn clean测试时,此过程将在您当前的用户下运行.但是,当由CI环境运行时,该进程归CI进程所有.因此没有相同的资源访问权限.

1- When mvn clean test is run from the IDE this process runs under your current user. However, when run by the CI environment, the process is owned by the CI process. so does not have the same access to resources.

2从IDE运行时,将弹出chrome.从CI环境运行时,我假设它默认将chrome以无头模式运行. 不是,您必须设置--headless参数,这样我现在可以使用的配置如下

2 When run from the IDE, chrome will pop up. When run from the CI environment I assumed that it defaulted chrome to run in headless mode. It does not, you have to set the --headless argument so my configuration that now works is as follows

public class GoogleChrome extends Base {
private static final Logger logger = LogManager.getLogger(GoogleChrome.class);
private String rootPath = System.getProperty("user.dir").replace("\\","/");


@Autowired
protected WebDriver driver;

public WebDriver startChromeDriver() {
    logger.info("Chrome driver path : " + rootPath + "/../Tools/Drivers/chromedriver.exe");
    System.setProperty("webdriver.chrome.driver", rootPath + "/../Tools/Drivers/chromedriver.exe");

    Map<String, Object> prefs = new HashMap<String, Object>();
    logger.info("Disabling Chrome's credentials service");
    prefs.put("credentials_enable_service", false);
    logger.info("Disabling Chrome's password manager");
    prefs.put("password_manager_enabled", false);


    final String regex = "^\\D*$";
    final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
    final Matcher matcher = pattern.matcher(System.getProperty("user.name"));
    boolean isHuman = matcher.matches();



    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", prefs);
    logger.info("Disabling Chrome's info bars");
    options.addArguments("disable-infobars");
    options.addArguments("--incognito");
    options.addArguments("--disable-gpu");
    options.addArguments("--no-sandbox");
    options.addArguments("--allow-insecure-localhost");

    if (isHuman){
        logger.info("Chrome starting maximized - isHuman: " +isHuman + " process run by " +System.getProperty("user.name"));
        options.addArguments("--start-maximized");
    } else {
        logger.info("Chrome starting headless - isHuman: " +isHuman + " process run by " +System.getProperty("user.name")) ;
        options.addArguments("--headless");
        options.addArguments("--window-size=1980,1080");
    }
    options.setAcceptInsecureCerts(true);

    try {
        logger.info("Killing Chrome browser");
        Runtime.getRuntime().exec("taskkill /F /IM chrome.exe");
    } catch (IOException e) {
        logger.error("Task Kill IOException : " + e.getMessage());
    }

    logger.info("Starting Chrome browser...");

    sleep(2);
    driver = new ChromeDriver(options);

    logger.info("Window size: "+ driver.manage().window().getSize());
    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
    return driver;
}

}

这篇关于GOCD管道,未设置Selenium ChromeDriver窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆