Is it possible to use ISelenium/DefaultSelenium without installing Selenium Server? - c#

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.

Related

Selenium webdriver - How to connect to the same firefox instance open by Visual Studio using C#

Hello friends. I would like some help.
I've been trying to use the same instance of Firefox window open by Visual Studio at first time.
The question is, how to pickup the same window browser and continue to testing without it close the browser and open again every time i want to do a testing?
I know there is a lot of questions about this topic, but some that I've found is applicable for old versions of selenium and some codes didn't work due to be deprecated.
What i can do with success:
I can work normally with traditional method to test a unit, opening Firefox at beginning and close after the end of test:
[ClassInitialize]
public static void InitializeClass(TestContext testContext) {
driver = new FirefoxDriver();
}
Then i commented the following lines to keep the window open when test is complete:
//driver.Quit();
//driver.Close();
//driver.Dispose();
What i can't manage to:
With searches I've been made, i read that we can connect to an existing session already open before. So i tried with the following:
[ClassInitialize]
public static void InitializeClass(TestContext testContext) {
FirefoxOptions options = new FirefoxOptions();
driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options);
//driver = new FirefoxDriver();
On the example above, I've commented driver = new FirefoxDriver(); and used the method FirefoxOptions instead of the deprecated DesiredCapabilities.firefox() and when i try to connect to the open firefox window, i got an error and i can't go on. On log, there's a line saying:
Was'n possible to copy the file "..\packages\Selenium.Firefox.WebDriver.0.27.0\build\driver\geckodriver.exe" to "..\bin\debug\geckodriver.exe"
The file geckodriver.exe (61484) is being used by another process
With this, i tried another different ways to reach what i expect like:
[ClassInitialize]
public static void InitializeClass(TestContext testContext) {
FirefoxOptions options = new FirefoxOptions();
driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options);
options.AddArgument("--marionette-port " + "2828" + "--connect-existing");
FirefoxDriverService ffDriverService = FirefoxDriverService.CreateDefaultService();
ffDriverService.BrowserCommunicationPort = 4444;
}
for last i tried to open a separated instance of Firefox to try to connect to like below:
firefox.exe --marionette -start-debugger-server 2828 -profile %temp%\FirefoxTEMP
I got success on open a instance of marionette,but i continuing unable to attach the test to this open window.
I appreciate your attention and forgive me for some newbie techniques i made.
Questions I've read:
How to connect Selenium to existing Firefox browser? (Python)
How to connect Selenium Webdriver to existing Firefox/Chrome browser session?
How to connect to an already open browser?
edit:
take a look on this thread to understand that it's a common request:
Allow webdriver to attach to a running browser - GitHub
You can use "detach" and change Firefox to Chrome(because I didn't see that option in Firefox). Link to link. Shortly, it keeps your browser open depending on the option "true"/"false".
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("detach", true);
You can use bad habits and simply use a global variable.
global browser

Selenium - start your normal chrome and not chromium

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.

Coded UI BrowserWindow casting to Selenium InternetExplorerDriver

I am creating a CodedUI project in Visual studio along with Selenium web driver.
I have CodedUI's BrowserWindow and a Selenium's InternetExplorerDriver.
Is there any way to cast CodedUI's BrowserWindow to Selenium's InternetExplorerDriver?
Example like:
BrowserWindow browser = new BrowserWindow.Launch("http://abc.xyz");
IWebDriver driver = browser;
Thanks in Advance
You can't, they are two entirely different things.
I assume you want to do some activities using selenium browser and some with Codedui browser. Then Launch browser using selenium and use codedui browser to attach it.
example
Selenium Browser
IWebDriver driver = new InternetExplorerDriver(ConfigurationManager.AppSettings["iedriver_exe"]);
driver.Navigate().GoToUrl(urlLink);
CodedUi Browser
var browser = BrowserWindow.Locate("browsertitle");

How to stop invoking of Firefox browser before opening any othre browser in selenium web driver cross browser testing

I am using selenium WD in C# for cross browser testing but facing a strange problem that when ever i run my test using Nunit firstly Firefox window will open & then my desired browser window will open & run the test on it(desired browser).
As per my knowledge if any system is not having Firefox installed in it then it fails the script.
So is there any way to change this default value of browser in selenium.
I am able to run tests on different browser, my problem is only that before opening my desired browser by default first system is opening firefox. which create issue for me & my tests.
public void SetupTest()
{
driver = new SafariDriver();
baseURL = "http://google.com/";
verificationErrors = new StringBuilder();
}
Most probably, somewhere in your code you are initializing the Firefox Driver. Search for this within you code:
new FirefoxDriver();
You could also debug to the line
driver = new SafariDriver();
and see if it has an assigned value already.
But I am also pretty certain that you are initializing a FirefoxDriver somewhere.

C# OpenQA and OperaDriver() problem. No Opera at selenium OpenQA v2.5

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 <==

Categories

Resources