How to run Chromedriver in Java Selenium in BOTH headless and incognito? - selenium-chromedriver

The problem I am trying to solve is to login into a site that has SSO. I will need to login with different credentials at times so I don't want to SSO in. Therefore, I will open up an incognito tab in Chrome so the SSO login popup will show up every time: chromeOptions.addArguments("incognito"); This works fine when I am running not in a headless mode and using Java Robot to input the credentials.
However, when I run this in headless mode: chromeOptions.addArguments("headless"); I am back to square one where I got SSO'd in into my personal account without the manual control of inputting in different credentials. That's not what's happening when I have incognito in non-headless mode.
How exactly do I configure my Chromedriver through Java to be BOTH headless and incognito?
I need headless mode because I need to run this inside a Docker container.

Related

Cypress can't open popup windows in headless Chrome

I'm new to Cypress and recently started implementing e2e tests for our system. A peculiarity of this system is that the authentication happens on a popup window.
I've already successfully created a simple test that loads the site, waits for the authentication to complete and then asserts that the page title is shown. This test runs without errors using the cypress client (cypress open), but when I run it in headless mode (cypress run --headless) the test fails.
When I see the video from the headless run, I don't see the popup window appear like it does when I run it with the GUI. Has anyone else had an issue like this where popup windows don't show on headless mode?
I also found this bug on the Chromium site related to issues displaying popup windows in headless mode, so it might be related to that, but the bug appears as closed.
I'm using Cypress 6.1.0 and Chrome 87
Thanks in advance for any help.
This was being caused by an issue with the integration of my website with another service that for some reason only occurred on headless mode. After fixing that, it works ok.

Select client certificate for authorization in Chrome headless mode

I'm trying to run tests in headless Chrome using Geb. Before enter the page, I have to select client certificate for authentication. How to do this in headless mode?
Robot class not working without UI.
Is there any way to handle certificate selection? I read about policies and AutoSelectCertificateForUrls but I can't find way to load policy from file or set this particular parameter as option/argument (Chrome on Linux).
In PhantomJS there is option to provide certificate as argument but how to do this using Chrome driver?
I had the same problem and ended up running in headful mode instead. There are some stuff required to be installed on the server though to be able to run Selenium in headful mode. I wrote an article on the subject using Selenium with .NET Core in linux with environment setup through docker.
https://sgedda.medium.com/running-selenium-with-chromedriver-together-with-client-certificate-set-in-headful-mode-with-net-a79bde19e472
Dockerfile
https://gist.githubusercontent.com/sgedda/584aa35a0d9162ad24f9cca836266959/raw/1fc0b4e6e8c76b791437bc847b67b2ed676c5d9b/Dockerfile

Selenium chrome windows authentication

I am automating a webapplication which uses windows authentication to sign-in.
I am using selenium specflow c# and running my tests on teamcity which uses grid in turn on the build agent.
However each of my row in Examples under scenario outline is testing with a different user.
We are using before scenario hook to create the Remote webdriver instance which is context injected to all the step bindings. However, at this point it is assuming that the user is the logged in user on the hub .
If I am using hub/grid, I am able to test with only one user login as the website takes the user credentials of the logged in user on the hub.
To work around this, we have used credentials embedded in the url. This happens in the Given step much after the hooks run.
While Chrome stopped the support for url credentials, how do I impersonate the users logging into the browser connected via remoteweb driver.
I have explored using process to create webdriver process and passing the credentials. I am not sure if this is the right way.
Or how do I make Chrome prompt for user credentials and stop auto logging as the hub user.
Because of this we are unable to upgrade the Chrome version.
I have explored so much but did not find a conclusive solution.
Regards,
Vijaya

Forcing proxy when running chrome over command line?

I'm trying to run headless e2e tests with chrome and selenium. But having issues getting chrome to adhere to a proxy server. When just trying to get chrome to use a proxy server as per the documentation, it gets completely ignored.
Is there anything obviously wrong with these configurations?
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --proxy-server='p-uk1.biscience.com:80'
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --proxy-server='http=p-uk1.biscience.com:80;https=p-uk1.biscience.com:80'
In each instance, by either checking a 'what is my ip' style website I get my usual IP. And when checking chrome://net-internals/#proxy the connection continues to show a DIRECT configuration.
Using a mac, but exact same issue when trying same configuration on my 14.04 ubuntu box :(

localhost refused to connect, after returning from paypal sandbox

Testing with PayPal checkout with Selenium & chrome webdriver.
I have tried using another domain name, localhost and 127.0.0.1
It may be important to note i am running inside a Vagrant machine (homestead)
Also tests run manually work.
I believe the issue to be an environment variable
PAYMENT_SANDBOX_PAYPAL_URL=http://localhost:8000/checkout/, however that is confusing as from what i understand there should be no difference when running automated tests with a webdriver.
Is this a networking issue with vagrant and my host? how would i diagnose this?
I understand this is a pretty specific question to the mentioned setup, however i think other new selenium users like myself will find it useful, especially when using codeception and laravel.
Perhaps it has something to do with whitelisting ip's?
Here is the current command.
java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalonjar -Dwebdriver.chrome.bin="/usr/bin/google-chrome" -Dwebdriver.chrome.driver="vendor/bin/chromedriver" -Dwebdriver.chrome.options="--whitelisted-ips=173.0.82.77,127.0.0.1"
I would guess chrome is running with different profile when launched manually (when it is able to load) and when launched through webdriver. WebDriver launches the browser in a different profile which may be very different than default profile which may include some settings related to proxy/networking.
From https://sites.google.com/a/chromium.org/chromedriver/capabilities
By default, ChromeDriver will create a new temporary profile for each session. At times you may want to set special preferences or just use a custom profile altogether. If the former, you can use the 'chrome.prefs' capability (described later below) to specify preferences that will be applied after Chrome starts. If the latter, you can use the user-data-dir Chrome command-line switch to tell Chrome which profile to use:
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
You can create your own custom profile by just running Chrome (on the command-line or through ChromeDriver) with the user-data-dir switch set to some new directory. If the path doesn't exist, Chrome will create a new profile in the specified location. You can then modify the profile settings as desired, and ChromeDriver can use the profile in the future. Open chrome://version in the browser to see what profile Chrome is using.
Are you sure, that PayPal Sandbox URL should be a local URL, not accessible from outside of your box?
Please provide more details! What web framework/web server do you use? What are libraries you used to get PayPal working.
I think, if the behavior differ when running Selenium, it is an issue completely related to WebDriver settings, or it's work together with Vagrant.