I have tried a lot of different stuff from the google and you-tube and this is where i land and i cannot get it to work, my connection to the Appium and emulator is fine also i have checked the adb devices everything is fine.
I am getting error for the Line driver = new AndroidDriver<IWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap, TimeSpan.FromSeconds(180));
These are the two errors which i get:
"cannot convert from 'System.Uri' to 'OpenQA.Selenium.Appium.Service.AppiumServiceBuilder'"
and
"cannot convert from 'OpenQA.Selenium.Remote.DesiredCapabilities' to 'OpenQA.Selenium.DriverOptions".
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.Android;
namespace UnitTestProject4
{
[TestClass]
public class UnitTest1
{
AppiumDriver<IWebElement> driver;
[TestMethod]
public void TestMethod1()
{
DesiredCapabilities cap = new DesiredCapabilities();
cap.SetCapability("deviceName", "Pixel 3a Pie 9.0 - API 28");
cap.SetCapability("platformVersion", "9.0");
cap.SetCapability("udid", "emulator-5554");
cap.SetCapability("appPackage", "org.mozilla.firefox");
cap.SetCapability("appActivity", "org.mozilla.gecko.BrowserApp");
cap.SetCapability("platformName", "Android");
driver = new AndroidDriver<IWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap, TimeSpan.FromSeconds(180));
driver.Navigate().GoToUrl("https://www.google.com");
}
}
}
You are very close, but I would make a few small tweaks. Your error messages are complaining about two things -- the use of DesiredCapabilities
instead of AppiumOptions
, and the use of new Uri("http://127.0.0.1:4723/wd/hub")
as a parameter for AndroidDriver<IWebElement>
.
To solve these issues -- instead of DesiredCapabilities
, I initialize my AndroidDriver
with AppiumOptions
. Additionally, you should try starting Appium through AppiumServiceBuilder()
and use that service to start your driver session. You should also specify a parameter for automationName
.
Here's what I always use to start a new mobile session on Android with C#:
// start appium service
var builder = new AppiumServiceBuilder();
var appiumLocalService = builder.UsingAnyFreePort().Build();
appiumLocalService.Start();
// create appium driver capabilities
var options = new AppiumOptions { PlatformName = "Android" };
options.AddAdditionalCapability("deviceName", "Pixel 3a Pie 9.0 - API 28");
// add app or appPackage / appActivity depending on preference
options.AddAdditionalCapability("appPackage", "org.mozilla.firefox");
options.AddAdditionalCapability("appActivity", "org.mozilla.gecko.BrowserApp");
options.AddAdditionalCapability("udid", "emulator-5554");
options.AddAdditionalCapability("automationName", "UiAutomator2"); // this one is important
// these are optional, but I find them to be helpful -- see DesiredCapabilities Appium docs to learn more
options.AddAdditionalCapability("autoGrantPermissions", true);
options.AddAdditionalCapability("allowSessionOverride", true);
// start the driver
var driver = new AndroidDriver<IWebElement>(appiumLocalService.ServiceUrl, options);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.