Coded UI BrowserWindow casting to Selenium InternetExplorerDriver - c#

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");

Related

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.

Is there any way to hide chrome selenium?

I have tried
options.add_argument("--headless")
driver = new ChromeDriver(options)
it's working fine but my requirement is to hide it after initialization.
As you can see here: How to execute tests with selenium webdriver while browser is minimized there is no way for the browser to be minified.
You could in theory move the browser out of view as described here https://sqa.stackexchange.com/questions/15484/how-to-minimize-the-browser-window-which-was-launched-via-selenium-webdriver
driver.manage().window().setPosition(new Point(-2000, 0))
Chrome headless is an instance of chrome. You can't start from normal mode and switch to headless mid test. Once you start testing with any kind of browser mode, you need to stick to it. There are some work arounds I've not tried with opening windows with code and continuing from the new window.
Use phantomJSDriver for Headless automation
WebDriver driver = new PhantomJSDriver();

c# selenium hide Internet Explorer browser window

I'm using selenium with c# and I would like to hide the internet explorer browser window. As far as I understood IE does not support headless browser.
For the particular case I'm working on, IE is the fastest browser, since I'm accessing internal company webpage.
Can you help me out?
I had the same problem and I'm happy to help you out.
I am still looking for a solution to start IE headless but with the minimized version I could also help myself.
here an idea:
IWebDriver webDriver;
public void StackTest()
{
webDriver = new InternetExplorerDriver();
webDriver.Manage().Window.Minimize();
}
as a little tip I recommend to keep IE waiting until everything is loaded:
webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);

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.

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

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.

Categories

Resources