I have docker-compose with 3 images - webserver, db and selenium.
I up it then exec into webserver and run php artisan dusk.
My app is a simple https page that returns Welcome in a few div.
But I got ErrorException: Undefined index: ELEMENT.
Selenium image: selenium/standalone-firefox.
test:
...
$this->browse(function (Browser $browser) use ($user) {
$browser
->visit('/home')
->assertSee('Welcome');
});
DuskTestCase.php
...
protected function driver() {
return RemoteWebDriver::create(
'http://selenium:4444/wd/hub', DesiredCapabilities::firefox()->setCapability(
'acceptInsecureCerts', true
)
);
}
This is due to an incompatibility between the geckodriver and Selenium:
https://github.com/facebook/php-webdriver/issues/492
For Firefox and Selenium you need to add enablePassThrough=false to the Selenium capabilities.
Something like:
protected function driver() {
return RemoteWebDriver::create(
'http://selenium:4444/wd/hub', DesiredCapabilities::firefox()
->setCapability('acceptInsecureCerts', true)
->setCapability('enablePassThrough', false)
);
}
should probably do the trick.
Related
I recently upgraded my Chrome/Chromedriver from v69 to the latest v76, and my suite of Selenium tests - which use BrowserMob Proxy to inject HTTP headers - have stopped working. The ChromeDriver will open the browser OK, but the headers are no longer being injected.
Chrome, Selenium and BrowserMob Proxy are now all on the latest versions:
Chrome: 76.0.3809.132
BrowserMob: 2.1.5
Selenium: 3.141.59
Does anyone know whether there are compatibility issues with the latest Chrome and BrowserMob? Or, can anyone spot an issue in my code?
Any help is much appreciated!
Here is my code:
Proxy seleniumProxy = null;
try {
String hostIp = Inet4Address.getLocalHost().getHostAddress();
proxy.setTrustAllServers(true);
proxy.start(0, Inet4Address.getByName(hostIp));
proxy.addRequestFilter((request, contents, messageInfo) -> {
headerMap.forEach((key, value) -> {
if (key != null && value != null) {
request.headers().add((String) key, value);
}
});
return null; //continue regular processing...
});
seleniumProxy = ClientUtil.createSeleniumProxy(proxy, InetAddress.getByName(hostIp));
seleniumProxy.setHttpProxy(hostIp + ":" + proxy.getPort());
seleniumProxy.setSslProxy(hostIp + ":" + proxy.getPort());
System.out.println("Created proxy on port " + proxy.getPort());
} catch (UnknownHostException e) {
LOG.error("unable to create BrowerMob proxy", e);
}
return seleniumProxy;
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 wrote test using TestNG and selenium.
code...
actions.sendKeys(Keys.chord(Keys.CONTROL, "a"));
actions.sendKeys(Keys.BACK_SPACE);
actions.build().perform();
code...
I wanted to delete text in login window using these sendKeys, with DataProvider
#DataProvider(name = "inputs")
public Object[][] getData() {
return new Object[][]{
{"000000000", true},
{"000000000", true}
};
}
Html:
<div><input type="tel" class="valid TextInput-kJdagG iVdKHC" name="recoveryPhone" id="eb69ff0b-3427-6986-7556-b7af40ffb156" aria-describedby="eb69ff0b-3427-6986-7556-b7af40ffb156" value="+48 "></div>
Error message:
Unable to read VR
Path1523545392670 Marionette INFO Enabled via --marionette
1523545393744 Marionette INFO Listening on port 52644
1523545394180 Marionette WARN TLS certificate errors will be ignored for this session
Test work as I expected on Chrome, but on firefox these sendKeys not always mark the text, and clear this text. In project I have to use action class. Why the test runs differently?
Check this post https://github.com/mozilla/geckodriver/issues/665 against your versions (browser, browser driver, selenium etc which are always sensible to include in any question), it could be a known bug with the geckodriver.
The post includes a work around of creating the chord in a different way, using:
List<CharSequence> keyWithModifiers = new ArrayList<CharSequence>();
keyWithModifiers.add(Keys.CONTROL);
keyWithModifiers.add("a");
String ctrlA = Keys.chord(keyWithModifiers);
textFieldElem.sendKeys(ctrlA);
This approach worked for me using Selenium 3.7.1 Java bindings, gecko driver 0.18.0 (64 bit) and Firefox 57.0.2 - 59.0
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.
Every time my webdriver tests login into the application, 'Do you want chrome to save your password' pop up appears.. Is there a way to avoid this??
Please help.
Thanks,
Mike
You need to configure the following chrome driver options:
chromeOptions: {
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
}
}
I'm using Python, and this worked for me:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option('prefs', {
'credentials_enable_service': False,
'profile': {
'password_manager_enabled': False
}
})
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('https://google.com')
Just add these preferences to your chrome driver options:
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
Yeah I just found the answer. I had to look into the Chrome's user data directory and find all the available chromeOptions the Preferences file. I'm on Centos 7 so the path looks like this:
~/.config/google-chrome/Default/Preferences
In order to remove the save password dialog, the config JSON chromeOptions section needs to have this:
chromeOptions: {
prefs: {
profile: {
password_manager_enabled: false
}
}
}
It really makes me happy that I have finally found these options, however, it still is disappointing that google or selenium didn't list all the configurable preferences.
Thanks to #karanvir Kang comment above, I added the following to my conf.js which I use when I call protractor. Example
protractor tests/conf.js --specs /tests/e2e/myspec.spec.js
And in my conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumPort: '4455',
baseUrl: url,
directConnect: false,
//getMultiCapabilities: helper.getFirefoxProfile,
capabilities: {
browserName: 'chrome',
chromeOptions: {
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
},
args: [
'--disable-cache',
'--disable-application-cache',
'--disable-offline-load-stale-cache',
'--disk-cache-size=0',
'--v8-cache-options=off'
]
}
},
You can also start the chromedriver in incognito mode to stop the infobars from appearing. Please note that the experience will be like the incognito mode. Command will be
chrome.exe --incognito if you are running from command line
you can add --incognito to chromeswitch array for executing from webdriver.
To provide a more complete picture, here is a working configuration for Watir in a Selenium Grid:
RSpec.configure do |config|
config.before :all do
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
}
}
)
#browser = Watir::Browser.new(
:remote,
url: "http://#{ENV.fetch('HUB_HOST')}/wd/hub",
desired_capabilities: capabilities
)
end
config.after :all do
#browser&.close
end
end
See a full proof of concept on github at docker-grid-watir.
I know this is pretty old, it has been answered correctly and all. Just wanted to give my 5 cents. If you are using Robot Framework, bellow is the way to do it.
open-browser
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys
${cred_dict}= Create Dictionary credentials_enable_service=${FALSE}
Call Method ${chrome_options} add_experimental_option prefs ${cred_dict}
Create Webdriver Chrome chrome chrome_options=${chrome_options}