How to enable remote debugging with chrome, selenium, chromedriver on mac - java

I want to re-use an existing chrome browser that's running on my mac.
From the internet it looks like I need to open chrome with arguments then run the java code and set the port number. Unfortunately I still get errors.
Open chrome on port 9222 from terminal:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port-9222 --user-data-dir="~ChromeProfile"
Java code in program to connect to chrome:
WebDriver dr = null;
location = "/Users/xx/Downloads/chromedriver";
System.setProperty("webdriver.chrome.driver", location);
ChromeOptions options = new ChromeOptions();
//options.addArguments("--remote-debugging-port=9222");
//options.setExperimentalOption("--remote-debugging-port", "localhost:9222");
options.setExperimentalOption("debuggerAddress", "localhost:9222");
dr = new ChromeDriver(options);
dr.navigate().to(myLink);
Netbeans keeps opening a random port and not 9222;
Starting ChromeDriver 9X.X.XXXX.XX (8c61b7e2989f2990d42f859cac71319137787cce-refs/branch-heads/4515#{#306}) on port 4188
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
What am I doing wrong?

Related

which chromedriver version supports electron app?

I try to run electron app using the following code:
#Test
public void testElectron() {
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(this.electronPath);
WebDriver driver = new ChromeDriver(chromeOptions);
}
But I get the following error:
Starting ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280#{#1761}) on port 37592
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
org.openqa.selenium.SessionNotCreatedException: session not created: This
version of ChromeDriver only supports Chrome version 87
Current browser version is 80.0.3987.165 with binary path src\main\resources\electron\electronApp.exe
Is there a specific chromedriver the is suitable for electron app (for selenium java)?
This error message...
Current browser version is 80.0.3987.165 with binary path src\main\resources\electron\electronApp.exe
...implies that the Chrome browser version is 80.0.
Solution
So as a solution you have to download the matching ChromeDriver
from ChromeDriver v80.0.3987.106 repository.

RemoteWebDriver with Edge Chromium 86/87 hangs with EdgeDriver.merge()

Selenium: 3.141.59;
Chromium Edge: Version 87.0.664.41 (Official build) (64-bit);
hub runs on linux, nodes on Windows 10.
I Would like to set up the RemoteWebDriver with Chromium Edge version 87. I have tried various options, and I am currently most successful with:
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
EdgeOptions edgeOptions = new EdgeOptions().merge(options);
RemoteWebDriver drv = new RemoteWebDriver(new URL(globalSetting.getHubUrl()),
edgeOptions);
drv.get("http://www.google.com");
With this the edge browser starts, but is unable to connect to the google url, because it is stuck in RemoteDriver setup. After some time, I get the a timeout and the message: WebDriverException: unknown error: unrecognized Chrome version: Edg/87.0.664.41
[With Chrome (google) it works fine.]
I red somewhere that this merge is not working with newer Chromium Edge and EdgeOptions should be used instead. But I only found Python code and it uses a field which EdgeOption in Java does not have (options.useChromium = true).
Has anybody been successful with Chromium Edge 86/87 and RemoteWebDriver in Java? If so could you provide a code example?

org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed using ChromeDriver Selenium in Jenkins on Ubuntu 18.04

Chrome is not stable on my Jenkins. When I run build 5 times, it runs 1 - 2-time success, and the other 3 times I have the above error.
Snapshot of the error:
Code for Chrome :
ChromeOptions options = new ChromeOptions();
System.setProperty("webdriver.chrome.driver","/usr/local/bin/chromedriver");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
driver = new ChromeDriver(options);
driver.get("https://mywebsite.com");
Some steps I have already taken :
Provided 777 permission to google chrome and chrome driver
Set : Start Xvfb before the build, and shut it down after to True in Jenkins build setting
ChromeDriver 81.0.4044.69
Google Chrome 81.0.4044.129
Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-99-generic x86_64)
This error message...
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Deep dive
Looking into the snapshot of the error stacktrace you have provided, though you mentioned about using ChromeDriver 81.0.4044.69 and Google Chrome 81.0.4044.129, still it appears there is a mismatch between the versions of the different binaries you are using, possibly Chrome browser is not installed at the default location within your system or due to JDK mismatch. Additionally, ChromeDriver 81.0.4044.69 (2020-03-17) was a bit unstable which was replaced by ChromeDriver 81.0.4044.138 (2020-05-05)
However, the server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:
1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
You can find a detailed discussion in What is default location of ChromeDriver and for installing Chrome on Windows
Solution
In case you are using the Chrome executable in a non-standard location you have to override the Chrome binary location as follows:
Code based solution:
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
ChromeOptions options = new ChromeOptions();
options.setBinary('/usr/bin/google-chrome'); //chrome binary location
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
//execute the remaining steps
driver.quit();
Additional considerations- Ensure the following:
JDK is upgraded to current levels JDK 8u251.
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v81.0.4044.138 level.
Chrome is updated to current Chrome Version 81.0.4044.138 level. (as per ChromeDriver v80.0 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
References
You can find a couple of relevant discussions in:
WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium?
Running Chromedriver on Ubuntu Server headlessly

"unknown error","message":"connection refused","stacktrace" while trying to use firefoxprofile through GeckoDriver with Selenium on Mac OS X

I am getting connection refused error while creating a firefox driver.
System.setProperty("webdriver.gecko.driver", "path to gecko driver");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.FATAL);
options.setAcceptInsecureCerts(true);
options.addArguments("-profile", "./firefoxprofile");
options.setHeadless(true);
LOGGER.info("Completed setting firefox optons");
WebDriver driver = new FirefoxDriver(options);
Log:
1550014357421 mozrunner::runner INFO Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "-marionette" "-profile" "./firefoxprofile" "-foreground" "-no-remote"
1550014357464 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1:61008
[GFX1-]: [OPENGL] Failed to init compositor with reason: FEATURE_FAILURE_OPENGL_CREATE_CONTEXT
Can't find symbol 'GetGraphicsResetStatus'.
1550014417545 mozrunner::runner DEBUG Killing process 38393
Exiting due to channel error.
1550014417592 webdriver::server DEBUG <- 500 Internal Server Error {"value":{"error":"unknown error","message":"connection refused","stacktrace":""}}
Web server is running and I could able to test it with curl command and I tried with 777 permissions on gecko driver bin file.
Also updated Gecko driver to latest version (0.24.0)
Your configurations looks good.
I had a similar problems in Linux.
In my case the solution was test with all versions of gecko driver and with one of them, it worked.
Also you can check if the o.s user of your IDE (eclipse, intellij) is the same user of the firefox. In my case, eclipse was starting with root but firefox could not start with root user.
I hope this help you.
While working with Selenium v3.x, GeckoDriver v0.24.0 and Firefox Quantum v65.0 to use a new Firefox Profile on every run of your Test Execution you can use the following code block :
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(new FirefoxProfile());
options.setLogLevel(FirefoxDriverLogLevel.FATAL);
options.setAcceptInsecureCerts(true);
options.setHeadless(true);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");
You can find a detailed discussion in Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
I was facing the same problem in Windows using python. Make sure that your Firefox browser version is also the latest one.
After searching a lot, I finally found it was because a previous instance of the browser was running. Keep in mind, not another instance like one opened by me but an instance which was previously opened by selenium. If you can, close all the background browser processes. I restarted my system and it works perfectly fine as long as I remember to do browser.quit().
If you stop the program before closing the object properly, there is a chance the background instance will keep running unless eclipse or whichever IDE you are using closes it.

Facing issue regarding Selenium(with java) and Firefox connectivity

Error: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.
Before all scripts were working fine..but now every script has stopped working.
I have updated Selenium version 3.0.1.(updated jar files), updated Firefox version 52.0.2 ...java version 8.
Please suggest what I am missing?
with Geckodriver version v0.15 , you have to use selenium 3.3.1
You would need to provide firefox binary location. One way of doing it is by the below code -
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //Location where Firefox is installed
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("moz:firefoxOptions", options);
FirefoxDriver driver = new FirefoxDriver(capabilities);
driver.get("http://www.google.com");
More info here - http://www.automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/
For Selenium 2.x later versions need to maintain geckodriver for firefox browser and if you find same issue then add binary path to your driver instance and try again.
Reference:
selenium 2.53.0 with firefox 46

Categories

Resources