Selenium, ChromeDriver start app - google-chrome

I would like to test a Chrome App with the help of WebDriver.
Normally when you want to directly start an App you pass the argument --app-id for e.g:
/opt/google/chrome/google-chrome --app-id=olddgoefnehjeogjhpcpolcnnifnglkp
Bur I'm not able to start my Chrome App with chromedriver:
I tried:
Selenium::WebDriver.for :chrome, :args => ["--app-id=olddgoefnehjeogjhpcpolcnnifnglkp"]
Steps to reproduce:
Go to the Chrome Web Store
Install an App
Go to preferences --> Extensions
Enable Developer-Modus
Now you can see the App-Id for eg: ID: olddgoefnehjeogjhpcpolcnnifnglkp
Try to start WebDriver with this option:
driver = Selenium::WebDriver.for :chrome, :args => ["--app-id=olddgoefnehjeogjhpcpolcnnifnglkp"]
Here is a list of arguments that should be valid for chromedriver:
http://peter.sh/experiments/chromium-command-line-switches/
Thanks for your help!

Related

Using acceptInsecureCerts with Headless Chrome and Selenium Webdriver, macOS, Rails, Capybara

Question
Does headless Chrome work with self-signed certificates via the Selenium Webdriver on macOS?
Info
I am attempting to get Rails system tests driven by headless Chrome over SSL.
I have a locally self-signed certificate that I pass the the ruby Puma application server to terminate SSL requests. In order to allow drivers to ignore SSL warnings on the locally signed certificate, I am using the acceptInsecureCerts flag to configure the driver capabilities.
I'm led to believe by this ticket in Chromium that this flag should be recognized as of Chrome 64+.
I can get tests to succeed with Chrome, Firefox, and headless Firefox. Tests do not pass under headless Chrome. I am using (at the time of this writing) what I believe to be the latest versions of Chrome and its variants.
Though folks in the Chromium ticket appear to be successfully running headless Chrome over locally-signed SSL with the Selenium webdriver, I have not found this to work with the setup described here. If my configuration is correct, then I am unsure if there is a limitation in headless Chrome on macOS, in Selenium webdriver ruby gem, or something else I haven't considered. If anyone has something similar working with Rails on macOS, I'd be interested to learn about your setup.
Source
Here is some code to show how I am configuring and running my RSpec/Capybara tests.
Test setup
# rails_helper.rb
# ... standard rspec rails helper setup omitted ...
Capybara.register_driver(:headless_chrome) do |app|
options = Selenium::WebDriver::Chrome::Options.new(
args: %w[--headless --disable-gpu --no-sandbox --disable-web-security]
)
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
acceptInsecureCerts: true,
)
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options,
desired_capabilities: capabilities
)
end
RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :headless_firefox
end
end
module SystemTestHelpers
def key_file_path
Rails.root.join("config", "ssl", "ssl-lvh.me.key")
end
def cert_file_path
Rails.root.join("config", "ssl", "ssl-lvh.me.crt")
end
def using_app_host(host)
original_host = Capybara.app_host
Capybara.app_host = host
Capybara.server = :puma, {
Host: "ssl://#{Capybara.server_host}?key=#{key_file_path}&cert=#{cert_file_path}"
}
yield
ensure
Capybara.app_host = original_host
end
end
RSpec.configure do |config|
config.include SystemTestHelpers, type: :system
end
Sample test
# spec/system/welcome_spec.rb
require 'rails_helper'
RSpec.feature "Welcome", :js, type: :system do
scenario "Visit homepage" do
using_app_host('https://subdomain.lvh.me') do
visit "/"
expect(page).to have_content('Welcome')
expect(page).to have_content('Your domain: subdomain.lvh.me')
expect(page).to have_content('Your protocol: https://')
end
end
end
Page content:
<div>
<h2>Welcome!</h2>
<p>Your protocol: <%= request.protocol %></p>
<p>Your domain: <%= request.host %></p>
</div>
If I swap out the driver for headless Firefox, configured as below, the tests will pass.
Capybara.register_driver(:headless_firefox) do |app|
options = Selenium::WebDriver::Firefox::Options.new(args: %w[--headless])
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(
acceptInsecureCerts: true,
)
Capybara::Selenium::Driver.new(
app,
browser: :firefox,
options: options,
desired_capabilities: capabilities
)
end
The complete source code for an app that reproduces the issue, and includes the code above is located here: https://bitbucket.org/rossta/system-test-demo.
Debug output
Here's a link to some debug output from running the test in either headless Chrome or headless Firefox: https://gist.github.com/rossta/b160204baa87a520e7888c19c8b1ed98.
Note in the output that the session response does not include the 'acceptInsecureCerts' capability for Chrome (test-headless-chrome.log, line 15) while in Firefox we do see the session include the flag (test-headless-firefox.log, line 22).
System
MacOS 10.13.6
Rails 5.2.1
Ruby 2.4.1
capybara (gem) 3.5.1
selenium-webdriver (gem) 3.14.0
chromdriver-helper (gem) 2.34
Chrome 68.0.3440.106. Have also tried
Google Chrome 70.0.3524.0 canary
Chromium 70.0.3525.0
From your log it shows that it's starting chromedriver v2.34. acceptInsecureCerts support wasn't added until 2.35 and you should really be running the latest (2.41 currently). Update your version of chromedriver and things should work.
caps = Selenium::WebDriver::Remote::Capabilities.firefox
caps['acceptInsecureCerts'] = true

EOFError, what happen to my minitest selenium test? how to fix it?

After my ubuntu updates, my minitest selenium test got an error, saying:
EOFError: EOFError: end of file reached
and it opens many blank google chrome windows as feature test total count.
my Ubuntu 16.04 updates was (yesterday everything works fine until the system made an update):
Commandline: aptdaemon role='role-commit-packages' sender=':1.105'
Upgrade: snap-confine:amd64 (1.0.42-0ubuntu3~16.04.1, 1.0.43-0ubuntu1~16.04.1), google-chrome-stable:amd64 (53.0.2785.143-1, 54.0.2840.59-1), ubuntu-core-launcher:amd64 (1.0.42-0ubuntu3~16.04.1, 1.0.43-0ubuntu1~16.04.1), libtracker-sparql-1.0-0:amd64 (1.6.2-0ubuntu1, 1.6.2-0ubuntu1.1)
in my test_helper.rb, I have:
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.current_driver = :selenium_chrome
Capybara.javascript_driver = :selenium_chrome
Capybara.default_driver = :selenium_chrome
I tried to uninstall Google Chrome and used Chromium browser and it works fine.
I wanna know how to do it with Google Chrome browser.
Do somebody knows how to fix it?
Please help!
I'm not sure if this is going to help, but I asked a similar question here and was able to determine that I was using a gem called chromedriver-helper. That readme said to try running chromedriver-update within the rails app and that cleared everything up.

Setting up Protractor with Microsoft Edge

I use CucumberJs and Gulp to run my e2e tests; However, I need to run them against Microsoft Edge. When I do gulp protractor, it successfully opens up both Chrome and Firefox, since neither of them require any drivers like IEDriver.exe or EdgeDriver.exe.
Could anyone point me to an article or show the steps below if it's simple on how to set up Protractor with Microsoft Edge?
I'm trying to achieve parallelism by executing my tests on multiple browsers; this is what my config looks like:
exports.config = {
framework: 'cucumber',
shardTestFiles: true,
maxInstances: 2,
multiCapabilities: [
{
'browserName': 'MicrosoftEdge',
'platform': 'windows',
}
},
{
'browserName': 'firefox',
loggingPrefs: {
driver: 'DEBUG',
server: 'INFO',
browser: 'ALL'
}
}],
//more configs here
}
I achieved the config right above, to run protractor e2e tests in parallel, using this article: http://blog.yodersolutions.com/run-protractor-tests-in-parallel/
Also one for IE driver would be just as helpful if you don't know how to set up Edge.
UPDATES:
From this link: https://msdn.microsoft.com/en-us/library/mt188085(v=vs.85).aspx; under the
Enabling WebDriver with Microsoft Edge:
Download a WebDriver language binding of your choice. Currently C# and
Java Selenium language bindings are supported.
I'm not using Java or C#, I am only using Javascript (Protractor); does that mean that the language binding for Javascript currenlty does NOT work for Edge browser?
In other words, we currently cannot automate the Edge browser using Protractor (Javascript)?
Any help much appreciated and I'll update this post if I find anything pertaining to setting up Protractor with Edge, been looking around the web for hours now.
After some struggle, I got Protractor to work on Microsoft Edge on my Windows 10 system.
Note: I'm using the Jasmine2 framework instead of Cucumber, but I believe the steps below should work for Cucumber as well. I'll try with Cucumber later and update here.
Here are the steps:
Get the Microsoft EdgeHTML version number in use in your system. In my case it is 15.15063. Take a note of the release number here. In this case it is 15063.
(Q.: How to get the Microsoft EdgeHTML version number?
A.: Edge browser > ... > Settings > About this app)
download the correct Release of MicrosoftWebDriver.exe from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
In my case I downloaded Release 15063. If you get the wrong release, then you are likely to run into an error like this error:
"This version of MicrosoftWebDriver.exe is not compatible with the installed version of Windows 10."
place the MicrosoftWebDriver.exe in the folder where the other drivers are like:
C:\Users\yourname\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\
Adjust your conf.js file. Essentially, this is what conf.js should have:
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: // or multiCapabilities:
{
'browserName': "MicrosoftEdge"
}
start the webdriver-manager like this:
C:\your\path>webdriver-manager start --edge C:\Users\yourname\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\MicrosoftWebDriver.exe
You are all set to run your Protractor tests on the Edge browser.
Good Luck!
In windows to download the MicrosoftEdge Webdriver for the HTML version >= 18 then follow the below steps
Open Command Prompt, issue the following command and wait until operation gets completed
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
Open the File Explorer and navigate to C:\Windows\WinSxS and search for MicrosoftWebDriver and it will display two results, copy the webdriver from the amd64_microsoft-webdriver-server-components10.0.18362.1_none and paste it in
/c/Users/Administrator/AppData/Roaming/npm/node_modules/protractor/node_modules/webdriver-manager/selenium
(Note: Using git bash, it's easy to copy the Webdriver)
In the config file of Edge browser, make the following changes
seleniumArgs:['-Dwebdriver.edge.driver=C:\\Users\\Administrator\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\webdriver-manager\\selenium\\MicrosoftWebDriver.exe'],
capabilities: {
'browserName': 'MicrosoftEdge',
'maxInstances': 1,
'platformName': 'windows',
'nativeEvents': false,
shardTestFiles: true,
},
Open the command prompt, and navigate to project repo and issue the following command to start the edge session
webdriver-manager start --edge "C:\Users\Administrator\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\MicrosoftWebDriver.exe"
I'm using Angular 9 with Edge 89 within linux
The following config worked for me
exports.config = {
directConnect: true,
chromeDriver: '/path/to/ms-edge/webdriver'
capabilities: {
browserName: 'chrome',
chromeOptions: {
binary: '/usr/bin/microsoft-edge'
}
},
},
Official WebDriver can be found here
Since Edge uses Chromium engine, we can reuse all chrome configs and just replace WebDriver and binary path.
Looks like the Protractor folks are now working on adding Edge support for Protractor. Take a look at the recently opened issue on GitHub.
Download the correct release of EdgeHTML webdriver ( https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ ), then settup the conf.js as:
seleniumArgs: ['-Dwebdriver.edge.driver=C:\\Program Files (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe'],
Capabilities: {
'browserName': 'MicrosoftEdge',
'maxInstances': 1,
'platformName': 'windows',
'nativeEvents': false,
}
Now Microsoft Edge is supported on Mac Operating System. So to setup in Mac follow below steps
Download the MicrosoftEdge WebDriver from the following link according to version of the edge browser configured in Mac
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Unzip the folder and copy the Unix executable file to following path
/usr/local/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/MicrosoftWebDriver
In the config file add SeleniumArgs attribute and capabilities
seleniumArgs : ['-Dwebdriver.edge.driver=/usr/local/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/MicrosoftWebDriver'],
capabilities: {
browserName: 'MicrosoftEdge',
platformName: 'Mac OS X',
browserVersion: '79.0.309.65',
maxInstances: 1,
shardTestFiles: true,
elementScrollBehavior: 1,
nativeEvents: false
},
In order to start the web driver with Edge Session, use below command..
java -jar -Dwebdriver.edge.driver=/usr/local/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/MicrosoftWebDriver /Users//Desktop/Project/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar -port 4444
Edge won't work with directconnect: true. Please refer below example.
directConnect: false,
multiCapabilities: [
{​​​​​
browserName: 'chrome',
chromeOptions: {​​​​​
args: ['--disable-popup-blocking'],
}​​​​​
}​​​​​,
{​​​​​
browserName: 'firefox'
}​​​​​,
{​​​​​
browserName: 'MicrosoftEdge'
}​​​​​
],
jvmArgs: [
'-Dwebdriver.chrome.driver=./src/driver/chromedriver_87.0.4280.20.exe',
`-Dwebdriver.edge.driver=${edgeDriver}`,
'-Dwebdriver.gecko.driver=./src/driver/geckodriver-v0.28.0.exe'
],
Use below code outside config if using mac
const edgeDriver =
process.platform === 'darwin'
? './src/driver/edgedriver_mac64_87.0.664.47/msedgedriver'
: './src/driver/msedgedriver.exe';

Chrome not working with Robotframework / Selenium2Library

I am trying to use Chrome browser with my Test cases. Same tests work fine with Firefox and PhantomJs.
However , Chrome browser starts but never opens a page.
I have installed
1. Chromdriver : port=9515 version=19.0.1068.0
2. Chrome : Version : 37.0.2062.120 (64-bit)
3. Selenium: Version : 2.42.1
4. RobotFramework : Version : 2.8.5
I think I have Paths variables configured accordingly as well.
google-chrome , starts Chrome
chromedriver , starts chromeDriver
Following line is responsible for starting chrome and opening page.
*** Variables ***
${BROWSER} Chrome
${MY-URL} http://www.google.com/
Open Browser | ${MY-URL} | ${BROWSER}
Errors :
Chrome:
WebDriverException: Message: u'Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date. Using Chrome binary at: /opt/google/chrome/google-chrome'
WebDriver Logs Shows Error
Initializing session with capabilities {
"browserName": "chrome",
"chromeOptions": {
"args": [ ],
"extensions": [ ]
},
"javascriptEnabled": true,
"platform": "ANY",
"version": ""
}
[1.001][INFO]: Launching chrome: /opt/google/chrome/google-chrome --disable-hang-monitor --disable-prompt-on-repost --dom-automation --full-memory-crash-report --no-default-browser-check --no-first-run --ignore-certificate-errors --homepage=about:blank
[46.004][SEVERE]: Failed to initialize connection
<br><br>
Can someone point something I am missing ?
Anyother way of debuging the problem ? Any Clue will be good.
Have you put chromedriver in your PATH ?
And do you run the test with current user or with root ?
Selenium needs chromedriver to call chrome, so you can download it from google.com and put it in /usr/bin, or just update your PATH environment variable.
Then, on Debian, root can't (otherwise with errors) call google-chrome browser, so try it with your account.
Hope it helpful.
NODE,
Please re-check your web driver, delete chrome web driver and download new web driver: Here
Check your VARIABLE NAME again! Do NOT use the "-" character to set a variable name like ${MY-URL}! You should change it => ${MY_URL}
You can try to turn of UAC or/and Firewall and try again.
As i know, when you use selenium2library, you don't need to set path to web driver(!?)
Hope it helpful.

Failed to read master_preferences file - Watir

Get this error when trying to drive chrome with watirs web driver ..... ie works fine.
C:\Users\rallen26346>irb
irb(main):001:0> require "watir-webdriver"
=> true
irb(main):003:0> browser = Watir::Browser.new :chrome
Started ChromeDriver
port=9515
version=26.0.1383.0
log=C:\Users\rallen26346\chromedriver.log
[4636:5120:0122/113039:ERROR:master_preferences.cc(104)] Failed to read master_preferences file at C:\Program Files\Google\Chrome\Application\master_p
references. Falling back to default preferences.
[4636:5120:0122/113039:ERROR:gpu_info_collector_win.cc(91)] Can't retrieve a valid WinSAT assessment.
[4636:5120:0122/113039:ERROR:bluetooth_adapter_win.cc(23)] NOT IMPLEMENTED
=> #<Watir::Browser:0x..fb028c9b0 url="about:blank" title="about:blank">
Try this:
browser = Watir::Browser.new :chrome