in my infrastructure, I have Selenium Hub and Selenium nodes connected to this Hub. I have nodes for each desktop browser I need to test. To run a test in my grid on let's say Chrome, I start the chromedriver with the following parameters:
java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server-standalone-2.52.0.jar -role webdriver -hub http://myseleniumhubip:4444/grid/register -browser browserName=chrome,platform=WINDOWS -port 5557
And I create my driver in the test like this:
DesiredCapabilities capability = DesiredCapabilities.Chrome();
driver = new RemoteWebDriver(new Uri("http://myseleniumhubip:4444/wd/hub"), capability);
And everything works as expected. Browser is launched on remote machine and test performs.
However, I would also like to test in Chrome on my real Android device. Problem is, I have no idea how to start chromedriver (what parameters to use), nor how to create RemoteWebDriver to accomplish this.
Could anyone please help me?
I have Android SDK installed on the machine with chromedriver
Phone is set into debugging mode
I'm using C# for my tests
Thank you!
If anyone's still struggling with this, the following approach works fine for me:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("androidPackage", "com.android.chrome");
driver = new RemoteWebDriver(new Uri("http://myseleniumhubip:4444/wd/hub"), chromeOptions.ToCapabilities());
Related
im looking example how can i start my normal google chrome in webdriver c#?
For now i use :
ChromeDriver driver;
public ChromeDriverService chromeDriverService;
chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("disable-infobars");
chromeOptions.AddExcludedArgument("enable-automation");
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
driver = new ChromeDriver(chromeDriverService,chromeOptions);
But it run my chromedriver.exe installed inside project. Can i just run my simple installed chrome? Without download any chromedriver.exe? It's important for me , because some website check if there is opened chromium with chromedriver.exe.
Is it possible to do that?
If you want not just open it but also perform some interaction with your site then you have to deal with Selenium and WebDriver.
You can try Python and undetected-chromedriver which has some workarounds preventing some systems to detect that your browser is running under webdriver control.
Unfortunately, it's the chromedriver.exe that lets you interact with Chrome so, without the driver, you wouldn't be able to interact with the actual browser.
If your issue is with chromium, try driving Mozilla with GeckoDriver
Selenium always uses chromedriver.exe for interacting with Chrome, I think you mean you want to load your default data directory. You can add a chrome option for this purpose:
chromeOptions.AddArguments(#"C:\Users\<your user name>\AppData\Local\Google\Chrome\User Data")
Take care, any other chrome must not be running that time with the same data directory. Like you may have run for your personal use.
You can also create a data directory somewhere else if you just want to show some realistic behavior to a website. But some websites are smart enough so it does not work every time.
I have an issue with starting a Chrome driver during initialization in a C# class when I try to start my application (NET Core 3.1) on a Windows Server 2012 R2 - it cannot start the driver directly and throws an exception (I used a remote debugger to find out):
Cannot start the driver service on http://localhost:{RandomPort}/
Besides this, when I start the driver from the application's directory on the server by PowerShell, it starts correctly:
C:\SomePath> .\chromedriver.exe
Starting ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280#{#1761}) on port {RandomPort}
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
But when I start the application on my local machine, it launches the driver and everything works fine.
Due to employer's security policy, I cannot install Chrome on the server so initialization happens as follows:
ChromeOptions options = new ChromeOptions();
options.BinaryLocation = $"{Directory.GetCurrentDirectory()}\\chrome\\chrome.exe";
WebDriver = new ChromeDriver(options);
On my local machine, right after the WebDriver = new ChromeDriver(options); I can use Selenium's APIs. But on the server it throws the exception.
I tried to launch the application on a different server with the same OS and it does not throw an exception. But it does not launch Chrome either - the chrome.exe processes are shown in the task manager, but the browser does not open and everything chashes when the app tries to interact with Selenium's APIs. Chrome's version fits with the driver's version. Do you have any idea why the exception ossurs?
UPD1:
If lauch chromedriver.exe from a command prompt and define allowed IPs, it allows to interact with it and opens the browser's window even from remote PCs:
c:\SomePath>chromedriver.exe --allowed-ips="{myLocalIP}"
Starting ChromeDriver 88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324#{#1784}) on port 9515
Remote connections are allowed by an allowlist (myLocalIP).
ChromeDriver was started successfully.
For a remote connection to the driver I tried the following code, but it forces me to change the other code since IWebDriver cannot be casted to ChromeDriver type:
DriverOptions options = new ChromeOptions();
IWebDriver wd = new RemoteWebDriver(new Uri("http://{remoteServerIP}:9515"), options);
wd.Navigate().GoToUrl("{someInternalUrl}");
The problem of direct initialization from the code is relevant on servers but does not reproduce on local machines.
UPD2:
I also tried to provide different accounts with different privileges to use in the application pool but it did not help - chrome.exe and chromedriver.exe processes were just launched under different accounts.
I have recently ugpraded to Chrome 65, ChromeDriver 2.37, and Selenium 3.11.0. I am trying to pass in chrome options into our remote web driver for our grid runs so that chrome starts maximized, but I can see from screenshots that the window is NOT getting maximized. Code looks like this:
var options = new ChromeOptions();
options.AddArguments("--start-maximized");
DriverThread.Value = new RemoteWebDriver(new Uri(remoteAddress), options);
We used to have to convert the chrome options to capabilities first but now the remote web driver takes in driver options as a parameter. Does anyone know why this isn't working? Am I doing something wrong?
Try it like
options.addArguments("start-maximized");
I used IWebDriver to control IE for testing before. But the methods supported for IWebDriver and IWebElement are so limited. I find that ISelenium/DefaultSelenium which belongs to Selenium namespace are very useful. How can I use them to control an IE without installing the Selenium Server??
Here's the constructor of DefaultSelenium:
ISelenium sele = new DefaultSelenium(**serveraddr**, **serverport**, browser, url2test);
sele.Start();
sele.Open();
...
Seems that I have to install Selenium Server before I create an ISelenium object.
My case is, I'm trying to build a .exe application with C#+Selenium which can run on different PCs and it's impossible to install Selenium Server on all PCs(you never know which one is the next to run the app).
Does anyone know how to use ISelenium/DefaultSelenium without installing the server?
thx!
There are some solutions in Java without using the RC Server:
1) For the selenium browser startup:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("safari");
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:4444/"), new URL("http://www.google.com/"), capabilities);
WebDriver driver = new RemoteWebDriver(executor, capabilities);
2) For selenium commands:
// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();
// A "base url", used by selenium to resolve relative URLs
String baseUrl = "http://www.google.com";
// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");
// Get the underlying WebDriver implementation back. This will refer to the
// same WebDriver instance as the "driver" variable above.
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getWrappedDriver();
//Finally, close the browser. Call stop on the WebDriverBackedSelenium instance
//instead of calling driver.quit(). Otherwise, the JVM will continue running after
//the browser has been closed.
selenium.stop();
Descripted here: http://seleniumhq.org/docs/03_webdriver.html
Google for something similar in C#.
Theres no other way to achieve that.
I am trying to use OperaDriver for selenium.
IWebDriver wd = new OperaDriver();
but using OpenQA.Selenium.Opera; does not exist. I can not find it in C# dll. I am using v2.5 drivers. Chroom, Ie, Firefox exist but no Opera. Where can i get it?
There is no native OperaDriver in the .NET bindings. Opera decided to implement their driver in Java, and not to implement the RemoteWebDriver JSON wire protocol. As such the only way to use the Opera driver from .NET is to use the .NET RemoteWebDriver class, along with an instance of the standalone Java Selenium server, which is available on the project downloads page.
Assuming you are on Windows:
The Operadriver is written in Java and not suported directly in C#, as it is mainatined not by the Selenium project team but by Opera.
To use it, you have to run the standalone Selenium webserver (from console on windows) before starting the test. get it here
you need to set the OPERA_PATH to point to your opera.exe file. Start the server with the command:
java -jar selenium-server-standalone-2.33.0.jar
i use a small bat for these two tasks:
SET OPERA_PATH="C:\Progra~2\Opera\opera.exe"
cd C:\pathToSeleniumJarFile
C:\Progra~2\Java\jre7\bin\java.exe -jar selenium-server-standalone-2.33.0.jar
C#:
testing with remotewebdriver object in your C# code to connect to it.
switch (WebBrowser)
{
case Browser.Chrome:
// chromedriver.exe has to be in the debug folder
ChromeOptions chrome = new ChromeOptions();
chrome.AddArguments("--ignore-certificate-errors");
webDriver = new ChromeDriver(chrome);
break;
...
case Browser.Opera:
//note: set OPERA_PATH environment variable (in cmd or global)
DesiredCapabilities opera = DesiredCapabilities.Opera();
opera.SetCapability("opera.profile", #"C:\OperaProfile");
webDriver = new RemoteWebDriver(opera);
break;
default:
throw new NotImplementedException();
if you want to manipulate the profile of the opera client (e.g. to accept untrusted certificates etc) you need to set
opera.SetCapability("opera.profile", #"C:\OperaProfile");
Copy an existing Profile to a location of your choice, here C:\OperaProfile.
==> Avoid spaces in all the pathes <==