When setting the window size for chrome to either maximized or 1980x1080 using
ChromeOptions.addArguments("--start-maximized");
or
driver.manage().window().setSize(new Dimension(1980,1080));
or
ChromeOptions.addArguments("window-size=1980,1080");
or
ChromeOptions.addArguments("--window-size=1980,1080");
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)
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)
message received is
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
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.
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
**EDIT 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)
EDIT 2
Added another argument i tried,
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- 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 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;
}
}