I'm currently trying to use Browsermob with WebdriverIO and I found this code on another answer, but when I run it, the firefox browser comes up and I see activity in the console windows I have selenium and browsermob-proxy running, but it does not go to the search.yahoo.com page. It just sits at a blank page and the tests ends (which says it passed, but that's something else)
I'm running the latest WebdriverIO and Browsermob on a Mac
Here's the code
var Proxy = require('browsermob-proxy').Proxy
, webdriverio = require('webdriverio')
, fs = require('fs')
, proxy = new Proxy()
;
proxy.cbHAR('search.yahoo.com', doWebio, function(err, data) {
if (err) {
console.error('ERR: ' + err);
} else {
fs.writeFileSync('stuff.har', data, 'utf8');
}
});
function doWebio(proxy, cb) {
var browser = webdriverio.remote({
host: 'localhost'
, port: 4444
, desiredCapabilities: { browserName: 'firefox', seleniumProtocol: 'WebDriver', proxy: { httpProxy: proxy } }
});
browser
.init()
.url("http://search.yahoo.com")
.setValue("#yschsp", "javascript")
.submitForm("#sf")
.end().then(cb);
}
have you tried using chrome. Maybe it'll work. To do so:
Add chromedriver from here to your /usr/bin
make change to above code like below (note upper case P in proxy)
start selenium server and browserMob as usual and run the test
desiredCapabilities: { browserName: 'chrome', seleniumProtocol: 'WebDriver', Proxy: { httpProxy: proxy } }
For those who come to this, with FireFox, you now need GeckoDriver installed to use FireFox with Selenium. https://github.com/mozilla/geckodriver/releases
Also, the BrowserMob proxy hasn't had a release since 2016. The BrowserUp Proxy is an actively maintained drop-in replacement https://github.com/browserup/browserup-proxy with support up to Java 11, active development, brotli support, security fixes, and more.
Related
I'm attempting to setup Selenium to test my electron app. So far I have the code from the Electron documentation, however, this only opens the HTML file, not my actual app. Here is my code:
import * as path from "path";
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
// The "9515" is the port opened by ChromeDriver.
.usingServer('http://localhost:9515')
.withCapabilities({
'chromeOptions': {
// Here is the path to your Electron binary.
binary: '../../node_modules/electron/dist/electron.exe'
}
})
.forBrowser('chrome')
.build();
const current_path = path.join(__dirname, "../../dist/public/index.html");
driver.get('file://' + current_path);
How can I get it to open my app?
I've been trying to figure this out for several days, and all the other articles and stackoverflow posts either point to Spectron (which is now deprecated) or don't explain how to open my own app and not a different website.
EDIT: I figured out that adding "args": ['--app=PATH_TO_PROJECT_DIR')] in the chromeOptions object , and changing the name to "goog:chromeOptions", makes it open to the correct file path, however, now I get the following error:
WebDriverError: unknown error: no chrome binary at ../../node_modules/electron/dist/electron.exe
Changing back to "chromeOptions" stops it from opening the app directory, but does open a blank chrome window.
The solution was to:
Replace '../../node_modules/electron/dist/electron.exe' with path.join(__dirname, '../../node_modules/electron/dist/electron.exe')
To change chromeOptions to goog:chromeOptions
To add "args": [path.join(__dirname, '../../')] to the goog:chromeOptions object.
Working Code:
import * as path from "path";
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
// The "9515" is the port opened by ChromeDriver.
.usingServer('http://localhost:9515')
.withCapabilities({
'goog:chromeOptions': {
// Here is the path to your Electron binary.
"binary": path.join(__dirname, '../../node_modules/electron/dist/electron.exe'),
"args": ['--app=' + path.join(__dirname, "../../")]
}
})
.forBrowser('chrome')
.build();
Trying to pick up the right combination of chrome options to disable annoying Password Manager popup after passing login form.
Here is how I create a driver:
Feature: Driver initialization
Background:
* configure retry = { count: 5, interval: 3000 }
Scenario Outline: using <config>
* def config = <config>
* set config.showDriverLog = true
* configure driver = config
* driver 'https://google.com'
* maximize()
* retry().waitUntil("document.readyState == 'complete'")
Examples:
| config |
| {type: 'chrome', executable: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', webDriverSession: { desiredCapabilities: { browserName: 'chrome', 'goog:chromeOptions': { credentials_enable_service: false, profile.password_manager_enabled: false }}}} |
Also I tried some other combinations with addOptions: [ ... ] and so on but nothing helps. Any ideas?
I had a similar issue but I found a workaround. Instead of using driver type to be chrome and pointing to the google chrome application installed locally download the chromedriver and use that. I used this on Windows and placed the chromedriver under C:/Windows/ folder. This did not bring up the password manager popup when executing the tests.
I've heard that using incognito mode can solve this.
Protractor creates a brand new Chrome profile every time it runs. So what i want to do it will enable popup for chrome browser every time when protractor test runs.
I don't want to use existing profile.Is there any way to do ?
You can create instance of chrome custom profile and it can be passed to capabilities.
export const chromeProfile = {
browserName : 'chrome',
maxInstances: 1,
chromeOptions: {
args: [
// mention list of all setting for chrome browser
//For example following two lines disable chrome popup
'disable-infobars=true',
'--disable-popup-blocking'
],
prefs: {
// disable password popup
'credentials_enable_service': false
}
}
};
I am using protractor and selenium with browser stack and trying to automate a webrtc web application, I need to get rid of browser asking for permission and using a fake stream instead of real camera and mic as available in chrome.
I have tried using these options they both do not work.
Option 1:
var capabilities = {
'browserName': 'iPhone',
'device': 'iPhone 6S',
'realMobile': 'true',
'os_version': '11.4',
"media.navigator.permission.disabled": true,
"media.navigator.streams.fake": true
};
Option 2
var capabilities = {
'browserName': 'iPhone',
'device': 'iPhone 6S',
'realMobile': 'true',
'os_version': '11.4',
'safariOptions': {
'args': ["--use-fake-ui-for-media-stream", '--use-fake-device-for-media-stream']
}
};
For building options I use:
var driver = new webdriver.Builder()
usingServer('http://hub-cloud.browserstack.com/wd/hub').
withCapabilities(capabilities).
build();
Currently, there is no such BrowserStack specific custom capability to pass fake media stream on Safari. Also, passing fake stream is not yet supported on Safari browsers. You can read about the issues below:
https://github.com/web-platform-tests/results-collection/issues/125
https://github.com/web-platform-tests/wpt/issues/7424
Also, there seem to be no such arguments supported for Safari browser. I reviewed the same in the sample SafariOptions examples here
It is always suggested to set the firefox profile in DesiredCapabilities and pass that through the wire ,where the hub is running . Like below
DesiredCapabilities caps = DesiredCapabilities.firefox();
FirefoxProfile profile=new FirefoxProfile(new File("Local Path to firefox profile folder"));
caps.setCapability(FirefoxDriver.PROFILE, profile);
URL url = new URL("http://localhost:4444/wd/hub");
WebDriver driver= new RemoteWebDriver(url,caps );
But sending the huge 87-90 mb profile info to hub over http ,for each selenium test case slowing down the test case execution .
I have tried configuring the grid node with "Dwebdriver.firefox.profile=E:\\Firefox_Profile_Location":"", property in json node config file like below.
{
"configuration":
{
.//Other Settings
.//Other Settings
.//Other Settings
"Dwebdriver.firefox.profile=E:\\Firefox_Profile_Location":"",
"maxSession":7,
"registerCycle":5000,
"register":true
},
"capabilities":
[
{"browserName":"firefox",
"seleniumProtocol":"WebDriver",
"maxInstances":5,
"platform":"VISTA"
}
]
}
But running with the above configuration is throwing below error .
WebDriverException: Firefox profile 'E:\Firefox_Profile_Location'
named in system property 'webdriver.firefox.profile' not found
Advanced thanks for any help on how to configure the firefox profile from the node side .
You need to provide the profile in the capabilities object as a base64 encoded zip:
var fs = require('fs');
capabilities: [
{
browserName: 'firefox',
seleniumProtocol: 'WebDriver',
maxInstances: 5,
platform: 'VISTA',
firefox_profile: new Buffer(fs.readFileSync("./profile.zip")).toString('base64')
}
]
Moreover Firefox creates the missing files for a given profile. So you should keep just the necessary files in the profile depending on your needs:
Preferences: user.js
Passwords: key3.db
logins.json
Cookies: cookies.sqlite
Certificate: cert8.sqlite
Extensions: extensions/
I think you'll have to use firefox profile name and not the location.
"webdriver.firefox.profile":"default"
Have a look at this and this and this
If you want know how to create a profile follow this and this