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;
}
}
Related
I'm using Selenium Grid to run some automated tests that always worked locally. I've created a RemoteWebDriver object, and used remoteDriver.setFileDetector(new LocalFileDetector()) to activate the local file detector. All of the pages I can find list this as the only solution, as if nothing can possibly go wrong with it.
In summary, selenium is definitely uploading the files from my local Windows filesystem, to Selenium Grid running on Linux. GeckoDriver can find it just fine, but ChromeDriver says it's not found:
invalid argument: File not found : /tmp/41dd2016f9974950127c20f7d25df461/upload7388365119198958794file/hasThemesWithImages.zip
(Session info: headless chrome=109.0.5414.74)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PAX-314945', ip: '192.168.50.241', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.16.1'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 109.0.5414.74, chrome: {chromedriverVersion: 109.0.5414.74 (e7c5703604da..., userDataDir: /tmp/.org.chromium.Chromium...}, goog:chromeOptions: {debuggerAddress: localhost:39795}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true, webdriver.remote.sessionid: 41dd2016f9974950127c20f7d25...}
Session ID: 41dd2016f9974950127c20f7d25df461
If I ssh to the remote host while it's still running, and type ls -l and paste in that long pathname, then I see the file is present. It's the correct size, and has global read permissions. I can even examine the zip contents. And yet, chromedriver gives the error above.
I started the grid server with a very simple java -jar selenium-server-standalone-3.141.59.jar command, with no other options, and am using Chromium in headless mode.
I have tried starting Chromium with and without --no-sandbox and --disable-dev-shm-usage as command line options.
I'm using Geb 3.4.1 and Groovy 2.x on the client side, and it looks like I'm doing everything correctly. I tried a few different tests that worked locally before, and added some logging in the test to confirm that driver.getFileDetector() returned the LocalFileDetector instance. Here is the relevant portion of my GebConfig.groovy file:
def remoteWebDriver(Capabilities capabilities) {
URL hubUrl = new URL("http://192.168.1.5:4444/wd/hub")
new RemoteWebDriver(hubUrl, capabilities)
}
FirefoxProfile myFirefoxProfile() {
// omitted; I hope it's not important.
}
environments {
gridFirefox { // file uploads work
driver = {
println "creating a RemoteDriver"
FirefoxOptions opts = new FirefoxOptions()
opts.addArguments("--headless")
opts.profile = myFirefoxProfile()
RemoteWebDriver remoteDriver = remoteWebDriver(opts)
remoteDriver.setFileDetector(new LocalFileDetector())
remoteDriver
}
}
gridChrome { // file uploads don't work
driver = {
println "creating a Chrome RemoteDriver"
ChromeOptions chrome_options = new ChromeOptions()
chrome_options.addArguments("--window-size=1600,1100")
chrome_options.addArguments('--headless')
//chrome_options.addArguments('--no-sandbox')
//chrome_options.addArguments('--disable-dev-shm-usage')
RemoteWebDriver remoteDriver = remoteWebDriver(chrome_options)
remoteDriver.setFileDetector(new LocalFileDetector())
remoteDriver
}
}
}
I am using selenium 3.141.59 with chrome 79 and chromedriver 79. Randomly I am getting an exception from RemoteWebDriver.get(url); and that session removing from the selenium server. But the Chrome window stays open. Because of that, I am not able to create new sessions with the same user directory. On my every attempt to create a new session, chrome window opens but session creation fails. So those All open Chrome windows causing memory leak! I tried to set timeout and browserTimeout from the server but it didn't help. Any idea what's happening?
I am starting server by:
java -jar -Dselenium.LOGGER.level=ALL selenium-server-standalone-3.141.59.jar -timeout 250 -browserTimeout 300
The exception I am getting randomly:
Caused by: org.openqa.selenium.WebDriverException: java.net.ConnectException: Connection refused (Connection refused)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'myhost', ip: 'myip', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.154-128.181.amzn2.x86_64', java.version: '1.8.0_201'
Driver info: mypackage.SeleniumHelper$2
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.88, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: /var/tmp/username...}, goog:chromeOptions: {debuggerAddress: localhost:35341}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 66ddc30a30affc4ba52a539bc41...}
Session ID: 66ddc30a30affc4ba52a539bc411ac2c
at sun.reflect.GeneratedConstructorAccessor1082.newInstance(Unknown Source) ~[?:?]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_201]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_201]
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:277) ~[selenium-remote-driver-3.141.59.jar:?]
... 65 more
My chrome options:
ChromeOptions options = new ChromeOptions ();
options.addArguments ("user-data-dir=/var/tmp/username");
options.addArguments ("disable-gpu");
options.addArguments ("disable-impl-side-painting");
options.addArguments ("disable-dev-shm-usage");
options.addArguments ("disable-infobars");
options.addArguments ("disable-gpu-sandbox");
options.addArguments ("no-sandbox");
options.addArguments ("disable-accelerated-2d-canvas");
options.addArguments ("disable-accelerated-jpeg-decoding");
options.addArguments ("test-type=ui");
options.addArguments ("no-proxy-server");
You need to consider a few things:
--user-data-dir: Refers to the directory where the browser stores the user profile. So you can't pass any arbitrary value. See: this and this discussion.
--disable-gpu: Disables GPU hardware acceleration. If software renderer is not in place, then the GPU process won't launch. However the purpose of the argument --disable-gpu was to enable google-chrome-headless on windows platform. It was needed as SwiftShader fails an assert on Windows in headless mode earlier. As you are on linux os you need to remove it. See: this and this discussion.
Ideally, you only add the arguments which are mandatory as per your Test Specifications.
Sample minimum code block:
public class A_Chrome
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
driver.quit();
}
}
Finally, when your program raises an exception, the WebDriver instance looses the control of the Browsing Context and both turns into a Zombie process. Hence google-chrome window stays open.
What if you use a try and except function? Where in except, you let the driver close chrome and reopen it again to create a new session?
try:
#set your try code here
except TimeoutException:
print('Page took too long to load or there was a different problem :(')
driver.quit()
try:
#set your new code here
except:
#set your except here
Or you could try to open an new chrome window after the except
Why this error TypeError: rootNode is null happens when taking screenshots? Is there a problem in HTML DOM structure which the developer should fix or is it a problem with Selenium version?
This error is happening when taking screenshot:
org.openqa.selenium.WebDriverException: TypeError: rootNode is null
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'linuxhost', ip: 'x.x.x.x', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-754.17.1.el6.x86_64', java.version: '1.8.0_202'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 60.8.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 6651, moz:profile: /tmp/rust_mozprofile.LlBKoU..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, platformVersion: 2.6.32-754.17.1.el6.x86_64, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 1afd06ed-4939-42c9-9d1d-51fa113dfe97
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:609)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:295)
dependency version:
Firefox: Mozilla Firefox 60.8.0
geckodriver: 0.23.0
selenium: 3.141.59
geb-spock:3.0.1
I just tried and it worked for me.
Firefox : 69.0 (64-bit)
Gecko Driver: v0.25.0
Webdriver: 3.141.59
FirefoxDriver fdriver;
System.setProperty("webdriver.gecko.driver", "/path/geckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
FirefoxOptions foptions = new FirefoxOptions();
foptions.merge(capabilities);
fdriver = new FirefoxDriver(foptions);
fdriver.get("http://demo.guru99.com/selenium/guru99home/");
File src = ((TakesScreenshot) fdriver).getScreenshotAs(OutputType.FILE);
try {
// now copy the screenshot to desired location using copyFile //method
FileUtils.copyFile(src, new File("path/fchart.png"));
fdriver.quit();
}
catch (IOException e) {
System.out.println(e.getMessage());
}
I found out why "TypeError: rootNode is null" error is happening.
This error happens if test is trying to taking screenshot before even the html page source is completely downloaded.
Adding a dynamic wait to wait for page to load completely did fixed this issue.
waitFor {
((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete")
}
takeScreenshot()
I am trying to use Browsermob proxy for achieving the basic http authentication across different browsers. But facing issues, tried to search for a solution on Browsermob's GITHUB page but didn't find much help there.
Here is my code for the achieving the auth:
// start the proxy
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start();
proxy.autoAuthorization("", "username", "password", AuthType.BASIC);
// get the Selenium proxy object
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
If I run above code on chrome then it still asks for auth. And nothing appears in the error console.
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + config.getChromeDriverPath());
WebDriver driver = new ChromeDriver(capabilities);
If I run above code on firefox then it gives error
Your connection is not secure.
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + config.getChromeDriverPath());
WebDriver driver = new ChromeDriver(capabilities);
And in the console following error appears:
FAILED CONFIGURATION: #BeforeClass launchBrowser
org.openqa.selenium.WebDriverException:
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'USER', ip: '192.168.43.57', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: false, browserName: firefox, browserVersion: 60.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 8180, moz:profile: C:\Users\USER\AppDat..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 6.3, proxy: Proxy(manual, http=tarun:49..., rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 6b53fdb7-78fe-44cb-a3b9-2592494ae7a5
What is not correct?
proxy.autoAuthorization("", "guest", "guest", AuthType.BASIC);
this feature does not work.
Use this instead:
String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString("login:password".getBytes()));
proxy.addHeader("Authorization", encodedCreadentials);
My automation test suite uses Selenium WebDriver with Protractor and Jasmine to run against a variety of browsers. When using GeckoDriver to run the tests on Firefox, I am intermittently getting an error message that just says "Failed: Timed out":
. ✓ WHEN I visit the favorites page
. ✓ THEN it should say I havent added anything
F ✗ WHEN I open the inspirations page
- Failed: Timed out
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'admins-MacBook-Pro-3.local', ip: 'fe80:0:0:0:10a7:9b8d:6ff5:f46%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: driver.version: unknown
F ✗ AND I click on an inspiration preview pane to open an inspiration
I have tried padding it with hard-coded sleep on either side, and I've searched for other errors, but everything else I can find in regards to Protractor timeouts is for other errors that have some kind of a description about what is actually timing out.
Has anyone seen JUST the message "Failed: Timed out" here who can help determine what might be timing out?
As requested, here is the gulp task that kicks off my protractor:
gulp.task('test-frontend-firefox', 'Run feature tests locally', function() {
gulp.src(['test/feature/**/*.spec.js'])
.pipe(protractor({
configFile: __dirname + '/../test/protractor_local_ff.conf.js',
args: ['--baseUrl', 'http://localhost:9099'],
}));
});
And here is protractor_local_ff.conf.js as referenced by the gulp task:
var private_config = require('./private.conf.js');
var golden_config = require('./golden.conf.js');
exports.config = {
params: {
private: private_config,
golden: golden_config,
localhost: true
},
onPrepare: function(){
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
},
framework: 'jasmine2',
// seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'firefox'
}
};
As you can see, it's set up to be able to run against the hosted app in either browserstack or on my localhost, but the error gets thrown intermittently in either environment.