Meaning of "browser" in Selenium's requested capabilities - selenium

I am developing functional tests with Behat, Mink and Selenium. I have long been perplexed by the "browser" item included in the Capabilities object that's created with each new session:
02:13:48.592 INFO - Got a request to create a new session: Capabilities
[{browser=safari, name=Behat feature suite, browserName=safari, [...] }]
As far as I can tell, only "browserName" has any effect - if I set "browserName" to "safari" and "browser" to any other value, then the new session will be created on a node that can run Safari.
So why does Mink include the value? It must surely have some purpose, but I haven't found any documentation explaining it.

A possible answer would be:
browser and browserName is the same capability for the browser to use.
If you are using capabilities parametter to set up the desired capabilities to use, then the browserName has priority.
If you are NOT using capabilities parametter you can also setup the browser name by using browser.
To get a better picture please take a look to getConfig method at arrayNode('selenium2') line from Extension.php located in vendor > behat > mink-extension > src.
Hope this will help you in getting an answer or at least point you to the right direction.

Related

The method attachToEdgeChrome() is undefined for the type InternetExplorerOptions using selenium-server-4.0.0-alpha-2

I want test the IE mode for Edge browser with Selenium. I found the solution on the MS site here:
https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/ie-mode?tabs=java
I am using the following code as given in the above link:
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
WebDriver driver = new InternetExplorerDriver(ieOptions);
I can get the error that the methods "attachToEdgeChrome()" and "withEdgeExecutablePath()" are not defined in the InternetExplorerOptions. Is there anything I am missing here?
Note: My selenium jar is selenium-server-4.0.0-alpha-2.jar
As per the ChangeLogs 0f Selenium v4.0.0.0-alpha-2:
Add Chromium-based Edge support. This involves adding a new Chromium driver to the tree too.
So ideally, the code block from the documentation Use Internet Explorer Driver to automate IE mode in Microsoft Edge should have worked seamlessly.
However, as per best practices instead of using the alpha and beta releases, you should always prefer the GA releases to execute your tests and you can pickup anyone from the following options:
Selenium v4.1.3
Selenium v4.1.2
Selenium v4.1.1
Selenium v4.1.0
Selenium v4.0.0

Configure Chrome options for Cypress

In Selenium projects, I'm used to configure the Chrome options. Is there a way of doing it in Cypress projects?
I need to test a website that is flagged like "unsafe" because of its obsolete certificates, and I need to bypass the "Unprotected connection" window.
What it looks like in Selenium projects:
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ()
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true)
WebDriver driver = new ChromeDriver (handlSSLErr);
Thanks in advance.
As per the documentation on cypress , you need to add below in your cypress.json file for achieving the same :
{
"chromeWebSecurity": false
}
Please check below link for more detailed info Here
Disabling my antivirus fixed the problem.

"Component not initialized" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" error with Selenium GeckoDriver and Mozilla

I am trying to execute my code in Firefox, sometimes it works but majority of time i get exception as:
[Exception... "Component not initialized" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: chrome://marionette/content/dom.js :: addEventListener :: line 67" data: no]
Its happening from last week, previously it was working fine for me.
NS_ERROR_NOT_INITIALIZED resembles an attempt which was made to use a component or object which has not yet been initialized. These components usually provide an initialization method, often called Init which must be called before any other methods which are being used.
However, this error message...
[Exception... "Component not initialized" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: chrome://marionette/content/dom.js :: addEventListener :: line 67" data: no]
...implies that the Marionette threw an error while invoking addEventListener as defined in dom.js
Your code trials and the relevant HTML DOM would have helped us to debug the issue in a better way. However it seems the addEventListener was invoked too early even before the DOM Tree was completely rendered. To be more specific addEventListener was invoked even before the Browser Client (i.e. the Web Browser) have attained 'document.readyState' equal to "complete". Generally once this condition is fulfilled Selenium performs the next line of code.
Solution
A quick solution will be to before you try to interact with any of the element on a fresh loaded webpage you need to induce WebDriverWait for either of the following expected_conditions:
title_is(title)
title_contains(title)
An example
Python:
Code Block:
driver.get("https://stackoverflow.com");
WebDriverWait(driver, 10).until(EC.title_contains("Stack"))
print("Page Title is : "+driver.title)
Console Output:
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers
Java:
Code Block:
driver.get("https://stackoverflow.com");
new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("Stack"));
System.out.println("Page Title is : "+driver.getTitle());
Console Output:
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers
Additional Considerations
Upgrade JDK to recent levels JDK 8u221.
Upgrade Selenium to current levels Version 3.141.59.
Upgrade GeckoDriver to GeckoDriver v0.25.0 level.
Ensure that the version of the binaries you are using are compatable.
You can find a detailed discussion in Which Firefox browser versions supported for given Geckodriver version?
GeckoDriver is present in the desired location.
GeckoDriver is having executable permission for non-root users.
Upgrade Firefox version to Firefox v69.0 levels.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your Test as a non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
References
You can find a couple of relevant discussions in:
WebDriverException: Message: Exception… “Failure” nsresult: “0x80004005 (NS_ERROR_FAILURE)” while saving a large html file using Selenium Python
[org.openqa.selenium.WebDriverException: Exception… “Component not initialized” error using GeckoDriver and Tor browser with Selenium Java
Outro
Occur the 'NS_ERROR_NOT_INITIALIZED' when switching the window to bottom dock.
It seems you're suffering from Geckodriver Issue 1263, you can try the following workarounds:
Update Selenium client library to the latest stable which is 3.141.59 as of now, it's better to use package management system like Maven or Gradle as update of dependencies libraries might be required. If you're not using Java check out Web - Desktop and Mobile Browsers article for code examples for different Selenium client languages like JavaScript, Python, C#, etc.
Make sure to use the latest version of Firefox
Make sure to use the latest version of Geckodriver
If you will be still experiencing problems you can consider raising a new issue in the Geckodriver project, be prepared to provide as much information as possible (the same applies to next questions here if any)
On my case, some configs were wrong. I was trying to block pop-up downloads, but something went wrong.Here is the code that I had to remove, and it worked (on this specific case):
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "C:\\Temp");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
profile.setPreference("pdfjs.disabled", true);
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.panel.shown", false);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, 1);
driver = new FirefoxDriver(capabilities);

Webdriver.io: what's the difference between the capabilities and desiredCapabilities keywords?

I'm using Webdriver.io to run UI tests in a Node environment.
I'd like to run Headless Chrome and came up with the following working configuration:
{
capabilities: [{
browserName: 'chrome',
args: ['--headless', '--disable-gpu']
}
}],
services : ['selenium-standalone'],
execArgv : ['--inspect']
}
However, I can't figure out whether capabilities is deprecated or not; I'm wondering because all the examples I see reference desiredCapabilities instead.
If I use desiredCapabilities though, then Chrome runs normally, not in headless mode.
I feel like I'm missing something, but I don't know what. Is there a significant difference between the two, and is one going away?
Thanks!
If you run webdriverio through the test runner (using a wdio.conf.js file), it uses capabilities.
If you run it in standalone mode (e.g. node myTest.js), it uses desiredCapabilities

Jmeter with selenium webdriver plugin-start firefox session without cleaning cookies/cache

I am using Jmeter 2.13 alongside with a selenium webdriver plugin. When I start my thread it opens a new firefox session with all the cookies and cache cleared. In a previous session I have made a sync that lasts almost 5 minutes that brings me in my app some products. I don`t want to sync everytime I start the thread.
Is there any way I could start the new firefox session without clearing cookies/cache ?
If my guess is correct, that Selenium is the one that is opening an instance of Firefox, please see below. If not, please provide more info about what you have setup with code examples.
By default Selenium is opening the Firefox in Safe mode, where a lot of stuff are disabled (like extensions, localstore settings, etc). This also means that you won't have any cache or cookies.
You can read more about this here.
To disable this, you need to set the `toolkit.startup.max_resumed_crashes` setting key in in `about:config` to `-1`.
Selenium code wise, this can be achieved by setting the preference in the FirefoxProfile. C# code to achieve it would look like this:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("toolkit.startup.max_resumed_crashes", "-1");
IWebDriver driver = new FirefoxDriver(firefoxProfile);
Looking into FirefoxDriverConfig.java source code the plugin creates new profile each time Firefox starts:
FirefoxProfile createProfile() {
FirefoxProfile profile = new FirefoxProfile();
String userAgentOverride = getUserAgentOverride();
String ntlmOverride = getNtlmSetting();
if (StringUtils.isNotEmpty(userAgentOverride)) {
profile.setPreference("general.useragent.override", userAgentOverride);
}
if (StringUtils.isNotEmpty(ntlmOverride)) {
profile.setPreference("network.negotiate-auth.allow-insecure-ntlm-v1", true);
}
profile.setPreference("app.update.enabled", false);
addExtensions(profile);
setPreferences(profile);
return profile;
}
So there are 2 options:
Get plugin source code and amend profile initialisation line to use your existing profile as:
FirefoxProfile profile = new FirefoxProfile("/path/to/firefox/profile");
See How do I find my profile page of Mozilla documentation for instructions on how you can locate your current profile directory.
Stop using WebDriver Sampler and switch to JSR223 Sampler instead, it supports all the languages WebDriver Sampler does and provides full control (you'll have to write all the code to configure, start and stop browser yourself)