WebdriverIO chromedriver preferences ignored - selenium-chromedriver

I am trying to setup preferences for Chrome in WebdriverIO, but it seems like they are being ignored by the driver. The preferences I am currently trying to set are these:
capabilities: [{
browserName: 'chrome',
'goog:chromeOptions': {
prefs: {
'download.prompt_for_download': false,
'download.directory_upgrade': true,
'download.default_directory': 'C:/Downloads',
'plugins.always_open_pdf_externally': true
}
}
}],
I have tried a couple of other preferences to test if it's these particular ones that don't work as well as tried providing the args property to the chromeOptions. Considering the arguments work fine, while none of the preferences I tried did, I've come to the conclusion that the prefs are simply being ignored.
Is anyone aware of the reason why this may be happening?

Related

Chrome Extensions: chrome.runtime.lastError: Internal error while updating dynamic rules

SOLUTION: Installed the latest version of chrome. All is well.
I am attempting to set dynamic rules to allow users to manually configure blocked and allowed sites using the declarativeNetRequest api. Specifically the updateDynamicRules method.
I attempt to add a new rule:
chrome.declarativeNetRequest.updateDynamicRules(
{
addRules: [
{
id: 1,
action: {type: "allow"},
condition: {urlFilter: "abc", resourceTypes: ["main_frame"]}
}
]
},
() => {
if (chrome.runtime.lastError)
console.log(chrome.runtime.lastError);
}
)
I've disabled all other extensions. I get the lastError: "Internal error while updating dynamic rules" I have attempted using another example here, but arrive to the same, rather vague result.
Has anyone else experienced this?
EDIT: Other things I have tried, in accordance to comments:
Changing the id of the dynamic rule in question
Uninstalling and reinstalling the extension
Thank you wOxxOm for the comment that helped solve my issue. "Might be a bug. Try Chrome Canary or the latest Chromium snapshot. To report the bug use crbug.com."
Simple installed the latest version of Chrome.

ERR_CONNECTION_REFUSED in localhost after GC update to 87.0.4280.66

I work with Visual Studio 2017 and develop asp.net core (2.2) app’s.
I have set IIS-Express as dev webserver and Google Chrome as default browser.
In the project settings, I have set http://localhost:14300 as dev-url.
Since the last chrome update Version 87.0.4280.66 (at 19.11.2020) the app is compiled, the chrome browser is started, but the url seems to be changed “on the fly” from http://localhost:14300 (as defined) to https:localhost (without port).
Therefore, an error message is showed in the browser:
ERR_CONNECTION_REFUSED
The app is loaded - if I paste the url (http://localhost:14300) in another Browser or a new chrome tab, the app is loaded.
So.. I assume a bug in the latest Chrome update or a compatibility issue VS2017 <-> ISS Express <-> GC
I already have searched the Internet and found nothing yet (further, I already sent as issue to Google) .
According to your description, I guess you may set the launchSettings.json's IIS Express's launch Url to "https://localhost".
I suggest you could check it to make sure the launch Url is right.
More details about the launchSettings.json, you could refer to below codes:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5761",
"sslPort": 44365
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "https://localhost",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AngularCore31": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
It seems as I have found the issue (I see no context, but this has solved my problem):
Note: Here ( 1 ) was https://localhost showed (instead of http://localhost:14300 as on the screenshot below).
After launch with debug to IIS press the (i) ( 1 ) symbol
Then select "Website-Einstellungen" ( 2 ) (website settings)
Then, I had to delete ( 3 ) all data to the website (localhost)
After doing that, the debug url (http://localhost:14300) was loaded correct again.
So... (for me) it seems as the update to Chrome Version 87.0.4280.66 had a problem regarding the already stored data and then (for whatever reason) has redirected
http://localhost:14300
to
https:/localhost

Setting sensors (location) in headless Chrome

Is it possible to set custom location coordinates with Chrome Headless? I can't find it in the
Devtools protocol
API. Is there a workaround available?
I googled it and got many methods. I try one by one, almost all of them turn out outdated. Then I find out a solution, use chrome devtools protocol to achieve that.
The small example code below, that it uses the most common tool selenium to execute chrome devtools protocol command.
import time
from selenium.webdriver import Chrome, ChromeOptions
options = ChromeOptions()
options.add_argument("--headless")
driver = Chrome(options=options)
driver.execute_cdp_cmd(
"Browser.grantPermissions",
{
"origin": "https://www.openstreetmap.org/",
"permissions": ["geolocation"]
},
)
driver.execute_cdp_cmd(
"Emulation.setGeolocationOverride",
{
"latitude": 35.689487,
"longitude": 139.691706,
"accuracy": 100,
},
)
driver.get("https://www.openstreetmap.org/")
driver.find_element_by_xpath("//span[#class='icon geolocate']").click()
time.sleep(3) # wait for the page full loaded
driver.get_screenshot_as_file("screenshot.png")
https://chromedevtools.github.io/devtools-protocol/tot/Emulation#method-setGeolocationOverride
and
https://chromedevtools.github.io/devtools-protocol/tot/Emulation#method-clearGeolocationOverride
... then you'll need to contend with ensuring that the correct location sharing setting is set within the user profile (chrome://settings/content/location - which is difficult to access due to being displayed via shadow dom, so using a preconfigured user profile will likely be easier --user-data-dir).
Edit to add: The above does not seem to be effective when using --headless. To resolve this I used https://chromedevtools.github.io/devtools-protocol/tot/Page#method-addScriptToEvaluateOnNewDocument with the following snippet:
navigator.geolocation.getCurrentPosition = function(success, failure) {
success({
coords: {latitude: <your_lat_float>, longitude: <your_lng_float>},
timestamp: Date.now(),
});
}

Webdriver.io enable flash for selenium-standalone

I'm writing acceptance tests on node.js using webdriver.io with selenium standalone server with latest Google Chrome driver.
I need to check that flash elements are clickable, but browser keeps to show me "Restart Chrome to enable Adobe Flash Player".
I've seen article that shows how to make Chrome driver to see custom profile on local machine, but I can't understand how to use this with my standalone server, since it has poor examples for configuration.
Can you explain the correct way to enable Adobe flash player for selenium standalone server in webdriver.io?
I found that the following worked:
browserName: 'chrome',
'goog:chromeOptions' : {
args: ['enable-features=RunAllFlashInAllowMode',
'disable-features=EnableEphemeralFlashPermission'],
prefs: {
"profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1,
'PluginsAllowedForUrls': '/route/to/site.com'
}
}
Using ephemeral mode will create a temp profile which allows the prefs to take effect:
https://developer.chrome.com/extensions/contentSettings
https://support.google.com/chrome/a/answer/3538894?hl=en
'goog:chromeOptions' was introduced as of selenium 3.8 github.com/elgalu/docker-selenium/issues/201 –
You can open up the profile which is a JSON blob and see the site added at profile.content_settings.exceptions.plugins and profile.content_settings.exceptions.flash_data.
It is very easy. you need to create a custom profile that you will always use to load your chrome with. then you configure the browser like you would do manually too. this means make website exclusions for flash. load some extensions or whatever you want to preconfig. with this code you can do it
// setup browser
var options = {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['user-data-dir=C:/Users/Administrator/AppData/Local/Google/Chrome/User Data/Profile 21v69',
'--lang=en']
} // chromeOptions: {
} // desiredCapabilities: {
} // options = {
var client = webdriverio.remote(options).init();
Also here are all command line commands for chrome
https://peter.sh/experiments/chromium-command-line-switches/
Another workable method. It's possible to allow flash plugin execution in the chrome config
You need to add in the wdio.conf.js three last preferences from code example
chromeOptions : {
args: chromeArgs,
prefs: {
"download.default_directory": process.env.PWD +'/download',
"profile.default_content_setting_values.plugins": 1,
"profile.content_settings.plugin_whitelist.adobe-flash-player": 1,
"profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1
}
}
I hope it will helpful

Protractor: launch chrome with network throttling enabled

The network throttling feature from Chrome DevTools is available in ChromeDriver-2.26+ according to this issue. How can I specify this in our protractor config file?
Based on searching around, I've tried variations of a couple things in the config file. I've added a networkConnectionEnabled property and a prefs block to chromeOptions, as below. (Note that I didn't do them both at the same time.)
multiCapabilities: [
{
'browserName': 'chrome',
'platform': 'ANY',
'networkConnectionEnabled': {'type': 'GPRS'},
'chromeOptions': {
args: [
'--lang=en',
'--window-size=1280,1024'
],
prefs: {
'net.throttling_enabled': 'true,50,20'
}
}
}
],
The second option I tried based on what I found here (line 1983). None of these change the behavior of the protractor run, which when I manually test and set the throttling triggers a certain condition in my code.
Edit: also tried adding something like this underchromeOptions: mobileEmulation: {networkConnectionEnabled: true, networkThrottle: '2G'}
According to changelog APIs for manipulating network emulation in Chrome were added in Selenium 3.4.0. And they are available in Protract 5.2.0 or newer.
Network conditions can be configured like below:
browser.driver.setNetworkConditions({
offline: false,
latency: 5, // Additional latency (ms).
download_throughput: 500 * 1024, // Maximal aggregated download throughput.
upload_throughput: 500 * 1024 // Maximal aggregated upload throughput.
});
This code should be placed in protractor.conf.js inside onPrepare function.