I want to know How does Desired Capabilities in Selenium WebDriver works internally??
For e.g. Suppose i have 2 different version of Chromedriver.exe on my machine. While executing code with Desired Capabilities, which exe it would pick and why?
How does Desired Capabilities internally decides from which path exe should be picked??
The DesiredCapabilities Class is used by the WebDriver instance (i.e. driver) to open the browser session with specified attributes. For example, the below code will:
Always use the "chromedriver.exe" from "C:\your_path\" directory.
Through DesiredCapabilities Class we can specify the location of the Chrome Executable.
Finally you need to pass the instance of DesiredCapabilities for driver to open the Chrome Application with those capabilities.
System.setProperty("webdriver.chrome.driver", "C:\\your_path\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.binary", "C:\\Program Files\\Google\\Chrome\\Application");
WebDriver driver = new ChromeDriver(capabilities);
driver.get("http:\\gmail.com");
It is always recommended to use the latest version of the drivers. The latest versions/releases of the drivers addresses the the bugs/defects of the previous build & also introduces new features. So, the idea of using another older version of drivers are not a part of good programming practice.
Let me know if this answers your question.
Related
Is driver.getContextHandles() or driver.context() removed in Selenium4 as these methods are coming for Appium driver?
I am Using Selenium 4.1.1 and JavaClient- 8.0.0-beta2.
Facing issue to find element while running a test in Hybrind app.
Scenario
A Web view is opening in App post click of an icon. Element not found exception is coming whereas element is uniquely found/identified in Chrome.
Any suggestions in this will help to procced further.
Regarding the question about driver.context()
This moved to io.appium.java_client.remote.SupportsContextSwitching interface which also includes the default implementation.
In your tests if you're using AppiumDriver, just cast the driver, like:
io.appium.java_client.remote.SupportsContextSwitching
((SupportsContextSwitching) driver).getContextHandles();
NOTE: To have this work without ClassCastException, the driver initially should be created as AndroidDriver or IOSDriver, e.g.:
BaseOptions options = new UiAutomator2Options().setAutoGrantPermissions(true);
AppiumDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), options);
More Details
I mention this, because driver.context() is a special case of a larger context.
There are a lot of changes in appium java client version 8 from version 7.
One of them: A lot of platform-specific and not defined by W3C WebDriver standard methods moved out to additional interfaces.
So pure AppiumDriver doesn't have this methods.
But if we look throught the code, e.g. to AndroidDriver, we see it implements 20+ additional interfaces:
public class AndroidDriver extends AppiumDriver implements
PressesKey,
SupportsRotation,
SupportsContextSwitching,
SupportsLocation,
PerformsTouchActions,
HidesKeyboard,
HasDeviceTime,
...
and the same for IOSDriver.
If you cannot find some method in AppiumDriver, try to go throught the interfaces, which AndroidDriver/ IOSDriver are implementing.
I am facing issue while launching my selenium script for edge browser.
I followed below steps-
Pre-Condition- I had Edge Legacy-Version 40 already installed on my system
1. Installed Edge Chromium Version LATEST-83...
2. Ran the automation selenide script on edge browser, it downloaded and used web driver version 83....
3. Our frameowrk is built like that it downloads the latest webDriver version at run time from github.bonagracia
4. Edge Legacy was replaced by Edge Chromium post installation and I could not access Edge Legacy
5. Due to some manual evaluation on my system, had to use Edge legacy so un-installed Microsoft Edge Chromium, but could not proceed ahead much, because there was some configuration change to be done at system level
6. Now, re-installed Microsoft edge chromium, but post re-installation I can access both Edge Legacy & Edge Chromium separately.
7. The automation scripts is now taking edge legacy-Version 40.... as the browser instead of edge chromium-Version 83.0.. & downloading this version from github.bonagracia.
Alternative-
Tried to disable the edge legacy in system properties, as cannot uninstall this software, because it is by default installed with Windows 10, but still that does not work. Selenide script is still downloading edge legacy web driver during runtime instead of edge chromium.
How can I ensure that my Edge legacy is disabled post installation of edge chromium and automation script uses the web driver manager for edge chromium rather than edge legacy.
Please suggest on this.
From your description, it seems that you will use the legacy version Edge and Microsoft Edge (Chromium version 83) version on the same machine. In this scenario, you could try to set the Edge driver directory path and the Edge browser's Binary Location when using selenium web driver.
To use the Legacy version Edge browser with Selenium web driver.
First, download the correct Microsoft WebDriver version.
Then, refer to the following code to assign the webDriver directory path.
// the edge driver directory path: MicrosoftWebDriver.exe
//var driverpath = #"C:\Windows\System32";
var driverpath = #"C:\Windows\SysWOW64";
//var driverpath = #"C:\Windows\WinSxS\wow64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_cf827c8a6da82156";
//var driverpath = #"C:\Windows\WinSxS\amd64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_c52dd23839475f5b";
using (var driver = new EdgeDriver(driverpath))
{
// Navigate to Bing
driver.Url = "https://www.bing.com/";
// Find the search box and query for webdriver
var element = driver.FindElementById("sb_form_q");
element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
driver.Quit();
}
To use the Microsoft Edge with Microsoft Edge webDriver.
First, download the correct Microsoft WebDriver version, then refer to the following code assign the Edge webDriver directory path the binary location.
#pragma warning disable IDE0017 // Simplify object initialization
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
#pragma warning restore IDE0017 // Simplify object initialization
edgeOptions.BinaryLocation = #"C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe";
var msedgedriverDir = #"E:\webdriver\edgedriver_win64_84_0_502\edgedriver_win64"; //msedgedriver.exe
var driver = new EdgeDriver(msedgedriverDir,edgeOptions);
driver.Navigate().GoToUrl("https://www.google.com");
Thread.Sleep(2000);
driver.Close();
[Note] Please remember to change the webdriver path and binary location to your owns. And in above sample, I'm using the C# selenium 4.0.0-alpha05 version.
Besides, here are some related articles might be is useful for you.
Access Microsoft Edge Legacy after installing the new version of Microsoft Edge
Use Microsoft Edge (Chromium) with WebDriver
I am using selenium webdriver with Testng framework. I have three different systems where the output of first system is the input to the second and output of second system is input to the third one.
first system has its own UI which can be only executed in Chrome and second and third has UI which can executed only in IE. Calls beteween systems are Asynchronous. Can some one help how to design this?
You will create 3 driver for each browser. You will keep your outputs as variable and passing to other system call.
You can create as many number of driver in a single script
Refer the below code. It's a just a example what you needed :-
System.setProperty("webdriver.chrome.driver","./src\\lib\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.google.co.in/");
String output1=driver.findElement(By.xpath("//input[#name='q']")).getText();
WebDriver driverIE=new InternetExplorerDriver();
driverIE.get("https://www.google.co.in/");
WebElement aa= driverIE.findElement(By.xpath("//input[#name='q']");
aa.sendKeys(output1);
WebDriver driverMFF= new FirefoxDriver();
driverMFF.get("https://www.google.co.in/");
String output3=driverMFF.findElement(By.xpath("//input[#name='q']")).getText();
In above demo script, I save the output of chromedriver and pass it to IE
Hope it will help :)
I'm setting up a Selenium Grid in order to cover a test matrix that needs to comprehensively cover the following combinations: Three servers (windows server 2003, 2008, and 2012) that provide identical services and ten clients (of flavors XP, win7, win8, and win8.1) that will be accessing each of the three servers to perform nearly identical tests. The three servers part is most likely irrelevant to this question, but I threw it in for context's sake. I'm configuring which servers to use via TestNG DataProviders.
The catch is that I want to test the interactions not just between different browsers and browser versions and operating systems, but also all four versions of windows.
From what I can tell the DesiredCapabilities class will only allow me to specify between between XP, VISTA, and WINDOWS enums. I have found this question and it has been answered Selenium Grid: Capabilities and Platform.WINDOWS7?
However I wanted to post a new question for three reasons. It deals with an old version of selenium. I'm using 2.39.0 and the solution references version 2.15. Also, I have four windows platforms, so I can't use the suggested solution unless I gut out part of my test matrix. That is undesirable, but not impossible. Finally, while I have a decent understanding of the trick being used, my understanding of how overriding the enum might affect my tests is pretty big unknown.
One possible workaround I've thought of depends on how the enum is used. If it just uses the enum to search all the nodes to find a machine that has been set up with some specified capability I could assign any of the remaining platform flags to my fourth OS profile. For instance, assign the XP flag to winXP, WINDOWS flag to win7, VISTA to win8, and finally the UNIX flag to win8.1. But if the enum is used for more intense purposes I'm up the proverbial creek. Also, defining a windows box with a UNIX platform flag just seems like bad programming practice, even if it were to work just fine.
I guess what I really want is way to tell the grid "Run this test on the machine with this IP address" rather than "run this test on a machine that matches these capabilities." Has this functionality been added to selenium, or is there a workaround I'm missing?
Thanks,
Jon
You can possibly specify the IP in the node configuration json file on your node machine:
{
"capabilities":
[
{
"platform": "WINDOWS",
"browserName": "firefox",
"maxInstances": 1,
"seleniumProtocol": "WebDriver",
"nodeip": "192.168.0.123"
}
],
"configuration":
{
"proxy":"org.openqa.grid.selenium.proxy.WebDriverRemoteProxy",
"maxSession":1,
"url":"http://192.168.0.99:4444/wd/hub"
}
}
And then request the specific node:
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability("platform", Platform.WINDOWS);
caps.setCapability("nodeip", "192.168.0.123");
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubUrl), caps);
Alternatively, you can possibly use the applicationName capability or the Browser Version capability to specify your IP/custom value as selenium grid does a simple string match on these. See the below google group discussions on using existing capabilities for identifying a specific node:
Using the applicationName capability
Using the Browser Version capability
We have ChromeDriverService class available in org.openqa.selenium.chrome ...
I understand this will help in starting the chrome driver on any port of the machine with the below code...
ChromeDriverService src = new ChromeDriverService.Builder().usingDriverExecutable(new File("Location of chromedriver.executable")).usingAnyFreePort().build();
src.start();
But not sure of how this is helpful for us in the automation, in which scenario this can be used ...
If we want to start the chrome browser with RemoteWebDriver having the DesiredCapability with Chrome, then we need to start running the selenium server standalone... the above ChromeDriverService is not useful there..
Please throw some light on ChromeDriverService
The purpose of ChromeDriverService is to manage a persistent instance of the ChromeDriver server.
Standard practice is to use the ChromeDriver class or the Selenium standalone server to obtain Chrome driver instances, but this practice sacrifices performance for convenience. In this scenario, each driver instance is associated with its own instance of the ChromeDriver server, which gets launched when the driver is requested and terminated when the driver exits. This per-instance server management adds overhead to test execution, both in terms of run-time and resource utilization.
Using ChromeDriverService, this overhead can be reduced to a minimum by enabling your test framework to launch a server instance at the start of the test suite and shut it down when the suite finishes. An example of this approach can be found on the ChromeDriver Getting started page under the heading Controlling ChromeDriver's lifetime.