I'm trying to run some unit tests using Selenium Webdriver and C#.Net for Firefox browser but I was unable to do it (Chrome and IE11 browsers are working smoothly).
Here is the info I gathered:
OS: Windows 10 Enterprise
Gecko driver version: geckodriver-v0.17.0-win32
Mozilla Firefox version: 54.0.1 (32-bit)
Environment Path variable already set under "C:\LEO\SELENIUM C#\Firefox"
Piece of Code:
using System;
using System.Text;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Firefox;
[TestFixture]
public class UnitTest3
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
[SetUp]
public void SetupTest()
{
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"C:\LEO\SELENIUM C#\Firefox");
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
driver = new FirefoxDriver(service);
baseURL = "http://www.dow.com";
verificationErrors = new StringBuilder();
}
}
Error:
Message: OpenQA.Selenium.WebDriverException : Unable to find a matching set of capabilities.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
StackTrace:
I will appreciate all your help, thanks.
First of all, you need Firefox: Developer Edition installed and updated.
That`s should be enough in your case.
Source with full guide.
Related
I am looking to use Selenium Chromedriver in an AWS Lambda function using C# but I am not having much luck... My initial error that i was getting was that "chromedriver.exe does not exist in /tmp/". Using the Webdrivermanager got me past this error but now i am having issues with permissions "Access to the path '/tmp/' is denied."
I have google my fingers off and have tried multiple ways of getting this to work. I bet it is something small that i am missing.
Any help would be greatly appreciated.
using System.Collections.Generic;
using Amazon.Lambda.Core;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using WebDriverManager;
public class Function
{
public void FunctionHandler(string input, ILambdaContext context)
{
var driver = GetDriver();
driver.Navigate().GoToUrl(input);
driver.Quit();
}
public IWebDriver GetDriver()
{
new DriverManager().SetUpDriver(
"http://chromedriver.storage.googleapis.com/75.0.3770.8/chromedriver_win32.zip",
"/tmp/",
"chromedriver.exe"
);
ChromeOptions options = new ChromeOptions();
options.AddArguments(new List<string>() {
"--no-sandbox",
"--headless",
"--disable-gpu",
"--homedir=/tmp"
});
return new ChromeDriver("/tmp/", options);
}
}
Looking into AWS Lambda Runtimes page
Operating system – Amazon Linux
AMI – amzn-ami-hvm-2017.03.1.20170812-x86_64-gp2
Linux kernel – 4.14.77-70.59.amzn1.x86_64
So I believe you should be using the Linux Chromedriver, to wit replace this line:
http://chromedriver.storage.googleapis.com/75.0.3770.8/chromedriver_win32.zip
with this one:
https://chromedriver.storage.googleapis.com/75.0.3770.8/chromedriver_linux64.zip
and maybe chromedriver.exe with just chromedriver
If you're going to invest into cloud-based web browser automation it might be easier to go for a specialized service like Saucelabs or Experitest
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
namespace SeleniumTidBits
{
[TestClass]
public class UnitTest1
{
static IWebDriver driverFF;
static IWebDriver driverGC;
[AssemblyInitialize]
public static void SetUp(TestContext context)
{
driverFF = new FirefoxDriver();
driverGC = new ChromeDriver();
}
[TestMethod]
public void TestFireFoxDriver()
{
driverFF.Navigate().GoToUrl("http://www.google.com");
driverFF.FindElement(By.Id("lst-ib")).SendKeys("Selenium");
driverFF.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);
}
[TestMethod]
public void TestChormeDriver()
{
driverGC.Navigate().GoToUrl("http://www.google.com");
driverGC.FindElement(By.Id("lst-ib")).SendKeys("Selenium");
driverGC.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);
}
}
}
Error:
Error Image
I'm just trying to run some random scripts to test webdrivers of Selenium. I'm using VS 2012 and i have imported driver from Nuget package.
For starting the test in Firefox, You will have to download geckodriver from here: https://github.com/mozilla/geckodriver/releases and use this code:
System.setProperty("webdriver.firefox.marionette", [path to the driver]);
WebDriver driver = new FirefoxDriver();
That Error states that Selenium WebDriver could not find the Firefox driver in your project folder.
Also, Webdriver no longer supports the default Firefox Driver. They are currently working on a new driver, called Marionette, for their new Gecko engine.(You have the link in the error)
More details on Marionette you can find here: Marionette
If you want to use the default driver, you should downgrade your Firefox. Version 45.0.1 works fine for me. And you should get Selenium Webdriver 2.53, the one you are using is 3.0.0 (The latest from NUget)
I have a question about referencing exe files for multiple browser testing in selenium NUnit with C#. I have added the additional code to get my tests to run in each browser but each time I run the tests, I get the error : OpenQA.Selenium.DriverServiceNotFoundException. My question is, is there anyway to add the reference without specifically laying out a path? I don't think that I would be able to add a path to the current code I have, without refactoring what I have. Thanks for your help in advance.
Test Fixture
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public class CustomerLogin<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
private string url;
[TestFixtureSetUp]
public void FixtureSetUp()
{
url = System.Configuration.ConfigurationManager.AppSettings["homeUrl"];
this.driver = new TWebDriver();
driver.Navigate().GoToUrl(url);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
}
Using statements
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
I believe you can set the path with something like this;
System.setProperty("webdriver.ie.driver", "C:\my\path\to\IEDriverServer.exe");
System.setProperty("webdriver.firefox.driber", "C:\my\path\to\FFDriver.exe");
Or, the better solution in my opinion is to add the drivers to your project and modify the build so that they end up in your drop folder. The code above is great for your local system but isn't portable. Most automation solutions are intended to 'work out of the box' which requires you to package your dependencies in the bin.
To package the drivers with your build; add a 'Drivers' folder to the project (right click the solution -> add -> new folder) then add the executables under there (right click the folder, add existing item). Now that you can see the driver exe in Solution Explorer right click and select properties, under Copy to Output Directory select 'Copy if Newer'.
After making some changed to the code I am able to run all tests on the big 3 browsers. I had to add the Chrome.exe and the IE.exe to the bin\Debug folder (The one with the WebDriver.dll's) Here are my changes to my code.
Test Fixtures
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public class CustomerLogin<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
private string url;
[SetUp]
public void SetUp()
{
this.driver = new TWebDriver();
url = System.Configuration.ConfigurationManager.AppSettings["homeUrl"];
driver.Navigate().GoToUrl(url);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
//Finding the customer login link and clicking it
driver.FindElement(By.Id("Homepage_r2_c14")).Click();
}
[TearDown]
public void TearDown()
{
driver.Quit();
}
}
I have a strange issue using Selenium Web driver with C#.
When I navigate to this webpage manually in Chrome or using the Firefox Selenium WebDriver then the following "Proovikabiin" link is displayed.
But when using the Chrome WebDriver the button is not displayed.
What in the world would cause this behavior difference? I prefer to keep my tests passing browser agnostic.
[Edit] Software Versions
Selenium.WebDriver, 2.26.0. Installed via NuGet.
Chrome WebDriver, 23.0.1240.0 from
here. The photo showing the button was created from the same chrome instance launched by the web driver, but just copy and pasting the link.
I'm using the built-in Firefox driver. Currently Firefox 17.0.1
installed on computer.
Here's some code.
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
namespace IntegrationMonitorLibrary.WebTests.FailFolder
{
[TestFixture]
class BrowserInconsistancyWithProovikabiinButton
{
[Test]
public void FirefoxShowsButton()
{
IWebDriver driver = new FirefoxDriver();
var url = "http://www.sangar.ee/et/mensshirts/meeste-sark-franco-s310166890.html";
driver.Navigate().GoToUrl(url);
var buttonId = "fitsmebutton";
driver.FindElement(By.Id(buttonId)).Click();
}
[Test]
public void ChromeDoesNotShowButton()
{
IWebDriver driver = new ChromeDriver();
var url = "http://www.sangar.ee/et/mensshirts/meeste-sark-franco-s310166890.html";
driver.Navigate().GoToUrl(url);
var buttonId = "fitsmebutton";
driver.FindElement(By.Id(buttonId)).Click();
}
}
}
I'm working on Automation framework using WebDriver with C#. Its working fine with Firefox but not with IE.
I am getting the following error:
IEDriverServer.exe does not exist-The file c:\users\administrator\documents\visual studio 2010\projects\TestProject1\TestProject1\bin\Debug\IEDriverServer.exe does not exist. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list
I am using IE 9 and Windows 7.
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.co.uk");
IWebElement queryBox = driver.FindElement(By.Name("q"));
queryBox.SendKeys("The Automated Tester");
queryBox.SendKeys(Keys.ArrowDown);
queryBox.Submit();
See also .
The IEDriverServer.exe (as well as ChromeDriver.exe) can be downloaded from:
http://selenium-release.storage.googleapis.com/index.html.
To get these to work with your Selenium tests, include the .exe in your test project, and set its properties to 'Copy Always'.
NOTE: You'll have to adjust the Add File dialog to display .exe files.
Doing this will resolve the error.
Here's a simple C# example of how to call the InternetExplorerDriver using the IEDriverServer.exe.
Refactor according to your needs.
Note: the use of driver.Quit() which ensures that the IEDriverServer.exe process is closed, after the test has finished.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.IE;
namespace SeleniumTest
{
[TestClass]
public class IEDriverTest
{
private const string URL = "http://url";
private const string IE_DRIVER_PATH = #"C:\PathTo\IEDriverServer.exe";
[TestMethod]
public void Test()
{
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = URL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true
};
var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
driver.Navigate();
driver.Close(); // closes browser
driver.Quit(); // closes IEDriverServer process
}
}
}
Per Jim Evans (who works on IEDriverServer)
The .NET bindings don't scan the %PATH% environment variable for the
executable. That means for the .NET bindings only, the
IEDriverServer.exe is expected to either be found in the same
directory as the .NET bindings assembly, or you must specify the
directory where it can be found in the constructor to the
InternetExplorerDriver class.
Failure to do one of these things (or to
set the UseInternalServer property in the InternetExplorerOptions
class) will cause the .NET IE driver implementation to throw an
exception. This is strictly by design, as we want people to begin
using the standalone IEDriverServer.exe, and the ability to use an
"internal" or "legacy" version of the server will be removed in a
future release.
https://groups.google.com/forum/?fromgroups#!topic/webdriver/EvTyEPYchxE
If you're working with Visual Studio and C# I've updated my NareshScaler nuget package to install IEDriverServer, ChromeDriver etc automatically, meaning you can get up and running quicker.
http://nuget.org/packages/NareshScaler
Code for WebDriver using java to run with IE. I believe this concept might be helpful for you using C#:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
File file = new File("C:\\Program Files\\Internet Explorer\\iexplore.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver(capabilities);
If above code doesn't work use the following instead of "File file = new File("C:\Program Files\Internet Explorer\iexplore.exe");":
File file = new File("F:\\Ripon\\IEDriverServer_Win32_2.25.2\\IEDriverServer.exe");
[Note: The version of IEDriverServer and Windows (32 or 64 bit) may vary individual to individual]
Give path only till folder where Internetexplorer.exe is located.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System.IO;
namespace Automation
{
class To_Run_IE
{
static void Main(string[] args)
{
//Keep Internetexplorer.exe in "D:\Automation\32\Internetexplorer.exe"
IWebDriver driver = new InternetExplorerDriver(#"D:\Automation\32\"); \\Give path till the exe folder
//IWebDriver driver = new Firefoxdriver()
driver.Navigate().GoToUrl("http://www.google.com/");
driver.Manage().Window.Maximize();
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Cheese");
query.Submit();
System.Console.WriteLine("Page title is: " + driver.Title);
driver.Quit();
}
} }
public IWebDriver IEWebDriver()
{
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
webDriver = new InternetExplorerDriver(ConfigurationSettings.AppSettings["IDEServerPath"].ToString(), options);//Path of ur IE WebDriver,Here I stored it in a AppConfig File
return webDriver;
}