Browser extension testing with selenium c# in Saucelabs - c#

Is it possible to test browser extensions with selenium c# in Saucelab. If so how and where to place the latest extension package in saucelab VM so that selenium launches the browser with the extension.

For Firefox and chrome it is possible by providing capabilities or profile. For Example in case of firefox:
File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen
WebDriver driver = new FirefoxDriver(firefoxProfile);

Related

Unable to start chrome process in .NET C# application

I am getting error on Selenium and unable to start chrome process. I am using Google Chrome Version 96.0.4664.45 (64-bit) and Selenium Web Driver 3.141.0
ChromeOptions chromeOptions = new ChromeOptions
{
BinaryLocation = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
};
chromeOptions.AddArgument("incognito");
using (ChromeDriver window = new ChromeDriver(chromeOptions))
{
try
{
log.Debug("Chrome window instantiated");
Did you install chromedriver too? If you haven't already: https://chromedriver.chromium.org/downloads

Selenium C# FirefoxDriver not working for latest Selenium & Firefox

The Selenium is supposed to work with Firefox without any drivers out of the box, however I found that it is not the case with the latest Selenium & Firefox (install just days ago, Selenium 3 & Firefox ERS 52.5).
I'm following "Selenium C# and NUnit Pain Free Start Guide" as a total newbie, but found the simple Selenium C# NUnit test is not working for Firefox.
Here is my C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
namespace NewSeleniumProject
{
[TestFixture]
public class MyFirstTest
{
IWebDriver driver;
[SetUp]
public void SetupTest()
{
// driver = new ChromeDriver();
driver = new FirefoxDriver();
//driver = new FirefoxDriver(new FirefoxBinary(#"C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"), new FirefoxProfile(), TimeSpan.FromMinutes(10));
//var options = new FirefoxOptions();
//options.BrowserExecutableLocation = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
//driver = new FirefoxDriver(options);
}
[Test]
public void myFirstTest()
{
driver.Navigate().GoToUrl("http://www.swtestacademy.com");
Assert.AreEqual("SW Test Academy - Software Test Academy", driver.Title);
driver.Close();
driver.Quit();
}
}
}
And the following are my journeys to get it working.
First of all, the driver = new ChromeDriver() works for me without any hitch.
When I was using 32b Firefox ERS 52 with driver = new FirefoxDriver();, I'm getting the "Unable to determine the current version of FireFox using the registry" error, however none of the answers from Unable to determine the current version of FireFox after updated to 28.0 solves my problem. So I tried the "Try uninstalling Firefox and then re-installing it. That's what I would do" one.
Wit 64b Firefox ERS 52 (and driver = new FirefoxDriver();), I'm getting the "OpenQA.Selenium.WebDriverException : Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed." error.
When using the var options = new FirefoxOptions(), for both 32b and 64b Firefox, I'm getting "OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:6985/session timed out after 60 seconds."
Again, the whole setup I'm following is from "Selenium C# and NUnit Pain Free Start Guide". What else I'm missing? Thx.
UPDATE:
This question is not about the error:
OpenQA.Selenium.DriverServiceNotFoundException : The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable.
which I've fixed by downloading the driver from https://github.com/mozilla/geckodriver/releases.
Make sure versions match first. Then try this way of doing for Firefox browser. I faced same challenges before but this way of calling Firefox solved the issue. Hope it might help
var binary = new FirefoxBinary(#"----Firefox.exe Local Path------");
var profile = new FirefoxProfile();
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"--GeckoDriver Path-----");
service.FirefoxBinaryPath = #"----Firefox.exe Local Path------";
driverInstance = new FirefoxDriver(service);
So yes, you will need to Dl the driver and place that in your bin folder of your application and pass the path location of the .exe to the driver service using the options() with {}.
I have the same thing, however there is a difference between the two. Firefox is installed in the 64 bit folder and chrome is located in the 32 bit folder (x86) Program Files and i believe this is where there issue lies in the Selenium only looks at the 32 bit folders for the applications .exe.
I ran into the same issue when i started using any other driver apart from edge.
another issue that you may run into with the new gecko driver is that firefox will not open on the requested URL. Note that this was in VB. Should be the same though. I may just run a test.

c# Selenium 2.53 moving to marionette driver after firefox upgrade to 47

I am trying to move into the upgraded firefox web browser automation using selenium. It seems that selenium needs marionette driver to continue working. I followed the instructions set by the devs,
downloaded the driver
renamed it to wires.exe
The following code didnt manage to properly set the PATH to a custom path.
System.Environment.SetEnvironmentVariable("webdriver.gecko.driver", "#C:\DOWNLOADS\wires.exe")
so i added wires.exe to the debug\bin folder and then wires.exe worked properly but i got the following error
System.InvalidOperationException was caught Message=entity not found Source=WebDriver
this is the code i use to start webdriver
FirefoxOptions option1 = new FirefoxOptions();
option1.IsMarionette = true;
option1.AddAdditionalCapability("marionette", true);
driver = new FirefoxDriver(option1);
I too got the "Entity Not Found" error using FirefoxDriver(new FirefoxOptions()). It appears to be looking for firefox.exe in C:\Program Files (x86)\Nightly and not finding it. I found this working :
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
IWebDriver driver = new FirefoxDriver(service);
I try with this and it's working:
Install FirefoxDevEdition
Download geckodriver.exe
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"C:\Users\jmalpartida\Downloads\geckodriver-v0.8.0-win32", "geckodriver.exe");
service.Port = 64444;
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Firefox Developer Edition\firefox.exe";
IWebDriver driver = new FirefoxDriver(service);
First of all, you need to add the driver to your system path, not as an env variable.
Second, you need to set the flag in a desired capability, not a Firefox option. See: Marionette Webdriver
As such for remote webdriver:
DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability("marionette", true);
var driver = new RemoteWebDriver(capabilities);
To add the webdriver to your windows path:
The easiest way is to open the start menu > search for environment > open edit the system environment variables > click on environment variables > search in the list for Path > click on edit > add ;C:\path\to\webdriver\location\wires.exe to the end and click save.
For your local (non-webdriver) tests you are right, you can run your webdriver using the following:
var driver = new FirefoxDriver(new FirefoxOptions());
You should not have to use
option1.IsMarionette = true;
option1.AddAdditionalCapability("marionette", true);
If you have set the driver path correctly in your path environment variable.

Blank firefox page launched from selenium

I am a new selenium user trying to launch Firefox from C# with selenium version 2.33.0
and Firefox version 20
Here is my code to launch firefox
var capability = DesiredCapabilities.Firefox();
Driver = new RemoteWebDriver(new Uri(Environment.SeleniumGridHubUrl), capability);
Here is my code to goto Url
Driver.Navigate().GoToUrl(Environment.Hostname[domain] + pathAndQuery);
The Firefox browser is launched successfully, however it is blank and does not display the webpage.
What I am missing here?
In your case if the gotourl is blank then you would get blank page.
This is what I usually do:
IWebDriver driver;
driver = new FirefoxDriver();
String baseURL = "http://localhost";
driver.Navigate().GoToUrl(baseURL + "/somepage.aspx");
This can happen with non compatible versions of Firefox. Make sure you turn off auto-update in the Firefox settings to avoid the latest version being installed by default.
To test that it is Firefox at fault change your WebDriver to another driver such as InternetExplorerDriver, ChromeDriver or SafariDriver.
Until Web Driver is supported, you can always downgrade your version of Firefox. Hope this helps.

Use chrome with Selenium 2.0 with C#

I have a problem with the ChromeDriver.exe When I run the test, a Google Chrome Window is open but then an error from the chromedriver console shows up. It says something like:
[0405/175241: WARNING:scoped_temp_dir.cc<15>] Could not delete temp
dir in dtor.
Can anybody help me?....I'm Using C# by the way.
I wanned to upload an image but I couldn't because I'm a new user...
-JM
Selenium WebDriver C# in ChromeDriver:
Prerequisite: Install Visual Studio (mine is VS 2017), Google Chrome browser
Steps to follow:
Open VS 2017 and create solution/project
Write a test using C# code as below:
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("Your Test URL");
Now install "Selenium.WebDriver.ChromeDriver" by following steps:
Right click on Project -> Manage NuGet Packages...
Click Browse at the top and search for ChromeDriver
Select "Selenium.WebDriver.ChromeDriver" and install it
Execute/Run your test
Instead of moving your chromedriver.exe, when creating a new instance of a ChromeDriver you may put the exe's file path as a parameter. This is the same as for IE.
For example: driver = new ChromeDriver("C:\ChromeDriverFolder"); will look for the cromedriver.exe in a folder on the C drive called 'ChromeDriverFolder'.

Categories