I have coded a simple test in visual studio using selenium which works in Firefox. However, I'm trying to run the same test on multiple browsers but I keep getting the same error that the drivers are not found in the directory or the PATH environment variable.
I have them downloaded and they are in the project I am working on. I've been trying all the different ways that I have found but nothing is working.
Can anyone help with this? Thanks :)
Here's a snippet of the code:
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
namespace SeleniumTest2
{
//1 test multiple browsers
[TestFixture(typeof(ChromeDriver))]
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class ClickTestMetaLearning3TestUser<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true;
[SetUp]
public void SetupTest()
{
this.driver = new TWebDriver();
//Runtime.getRuntime().exec("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255");
baseURL = "http://url";
verificationErrors = new StringBuilder();
}
We have had to explicitly tell the ChromeDriver where it is located when constructing it :
_chromeDriver = new ChromeDriver(#"<path to the chromedriver.exe");
Related
I can't seem to figure out what is going on here.
I have posted below my code and a photo:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
ChromeOptions options = new ChromeOptions();
options.AddExtensions(new File("pathtoextentions.crx"));
IWebDriver driver = new ChromeDriver(options);
//Test Opening Website
driver.Navigate().GoToUrl("https://google.com");
}
}
}
I have also uploaded a photo here where it show my error is on new File: https://ibb.co/Lk72dsD
Error CS0712 Cannot create an instance of the static class 'File'
What am I doing wrong?
File is a static class, you can't create instances of it like new File().
Looking at ChormeOptions.AddExtensions, it accepts an array or an IEnumerable of string.
So, we could use an array in your case. To do so, replace this:
options.AddExtensions(new File("pathtoextentions.crx"));
with this:
options.AddExtensions(new[] { "pathtoextentions.crx" });
I am totally new to automation and new to Specflow and trying to follow an online course, but I get this error and I am unable as of yet to resolve. I have tried looking on the internet but I do not follow how to apply the information to get rid of the error in my script. I have restarted my laptop and the class and I checked the nugget to see that Selenium.WebDriver.ChromeDriver' has installed. There is a course tutor but he has not responded to a query I raised 2x days ago. So I thought I would try online forums such as this, as it helps to get timely feedback.
Here is the code, any help resolving this is appreciated. Thanks.
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
namespace UdemyTestProjectJK1.Utilities
{
[Binding]
public class Hooks1
{
public static IWebDriver driver;
[BeforeScenario]
public void BeforeScenario()
{
driver = new Chromedriver();
driver.Manage().Window.Maximize();
}
[AfterScenario]
public void AfterScenario()
{
driver.Quit();
}
}
}
Instead of this line in your code :
driver = new Chromedriver();
do this :
driver = new ChromeDriver(#"C:\my\path\to\chromedriver\directory");
and download chromdriver from here and put it above with full path.
or
if Install Selenium.WebDriver.ChromeDriver from NuGet and then you can do the following:
driver = new ChromeDriver(Environment.CurrentDirectory);
I am getting 'Method must have a return type' whenever i tried to run this project. I would appreciate your help as i have been struggling to resolve this issue to no avail. Thank you
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.Enums;
using System.Threading;
namespace AppiumTest
{
public class Class1
{
AppiumDriver driver;
TestMethod1()
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("MobileCapabilityType.deviceName", "Test");
capabilities.SetCapability("MobileCapabilityType.deviceName", "Test");
capabilities.SetCapability("MobileCapabilityType.platformVersion", "Emulator");
capabilities.SetCapability("MobileCapabilityType.platformName", "Android");
capabilities.SetCapability("MobileCapabilityType.appPackage", "");
capabilities.SetCapability("MobileCapabilityType.appActivity", "");
driver = new AndroidDriver<AppiumWebElement>(new Uri("http://127.0.0.1.4723/wd/hub"), capabilities);
Thread.Sleep(5000);
driver.FindElementById("com.paypoint.energycontrols:id/btn_sign_in").Click();
driver.FindElement(By.Id("com.paypoint.energycontrols:id/et_email")).SendKeys("");
driver.FindElement(By.Id("com.paypoint.energycontrols:id/et_password")).SendKeys("");
driver.FindElementById("com.paypoint.energycontrols:id/btn_show_pass").Click();
driver.FindElementById("com.paypoint.energycontrols:id/btn_sign_in").Click();
}
}
}
Your method declaration has only method name. In C# methods must have return type and a name. Add a void keyword before TestMethod1():
void TestMethod1() { ... }
I am trying below code with AppiumDriver but getting error. I am using beloe code and using appium.dotnet driver version 1.5.1.1
using NUnit.Framework;
using System;
using System;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium.Interfaces;
using OpenQA.Selenium.Appium.MultiTouch;
using OpenQA.Selenium.Interactions;
namespace TestAutomation_AppiumFramework
{
[TestFixture()]
public class TestAppium
{
private AppiumDriver<AppiumWebElement> driver;
private static Uri testServerAddress = new Uri("http:127.0.01:4723/wd/hub"); // If Appium is running locally
private static TimeSpan INIT_TIMEOUT_SEC = TimeSpan.FromSeconds(180); /* Change this to a more reasonable value */
private static TimeSpan IMPLICIT_TIMEOUT_SEC = TimeSpan.FromSeconds(10); /* Change this to a more reasonable value */
[TestInitialize]
public void BeforeAll()
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("device", "Android");
capabilities.SetCapability(CapabilityType.Platform, "Windows");
capabilities.SetCapability("deviceName", "H30-U10");
capabilities.SetCapability("platformName", "Android");
capabilities.SetCapability("platformVersion", "4.3");
capabilities.SetCapability("appPackage", "com.android.calculator2");
capabilities.SetCapability("appActivity", "com.android.calculator2.Calculator");
driver = new AppiumDriver(testServerAddress,capabilities, INIT_TIMEOUT_SEC);
driver.Manage().Timeouts().ImplicitlyWait(IMPLICIT_TIMEOUT_SEC);
}
Getting error -on this line -
driver = new AppiumDriver(testServerAddress,capabilities, INIT_TIMEOUT_SEC);
Saying Using the generic type 'OpenQA.Selenium.Appium.AppiumDriver' requires 1 type arguments]
AppiumDriver is an Abstract class. You have to initialize one of the concrete classes such as AndroidDriver or IOSDriver and define the argument type associated with it.
I have implemented alannings example from the below link: , however, as each test runs, they all come back with GoogleTest as there name.I would like ot be able to get each result append with the browser it ran in. What would be the best approach
Run Selenium tests in multiple browsers one after another from C# NUnit
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium.Support.UI;
namespace UnitTestProject1
{
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public class agentLogin<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
[SetUp]
public void CreateDriver () {
this.driver = new TWebDriver();
}
[Test]
public void agentLogin_Smoke() {
driver.Url = "http://dev.URL.com/Login/Index.aspx";
Assert.IsTrue(driver.FindElement(By.Id("lblHeader")).Displayed);
//Agent Login name
var agentLogin = driver.FindElement(By.Id("tbLoginName"));
agentLogin.Clear();
agentLogin.SendKeys("userID");