Reputation: 111
I can't find any documentation outlining how to initialize an appium android driver.
I had this test somewhat working with appium 3.0.0.2
and selenium 3.11
but then received the following error when trying to find an element by class name:
OpenQA.Selenium.InvalidSelectorException: 'Locator Strategy 'css selector' is not supported for this session
Ideally I don't want to go back to an older version of selenium as I already have a set of working tests using 3.14
. This is my test at the moment, and I cant find clear documentation telling me how to implement an appium driver in C#
.
public void androidTest(){
AndroidDriver<AndroidElement> driver;
DesiredCapabilities cap = new DesiredCapabilities();
cap.SetCapability("deviceName", "myName");
cap.SetCapability("platformName", "Android");
cap.SetCapability("automationName", "UiAutomator2");
cap.SetCapability("appPackage", "myPackage");
cap.SetCapability("appActivity", "myActivity");
Uri url = new Uri("http://127.0.0.1:4723/wd/hub");
driver = new AndroidDriver<IWebElement>(url, cap);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
driver.FindElementByName("android.widget.EditText").SendKeys("testString");
}
I get the following two error messages
Argument 1:
cannot convert from
'System.Uri'
to'OpenQA.Selenium.Remote.ICommandExecutor'
Argument 2:
cannot convert from
'OpenQA.Selenium.Remote.DesiredCapabilities'
to'OpenQA.Selenium.DriverOptions'
ArenaTests
What arguments do I need to pass into this constructor to get this setup working?
Upvotes: 0
Views: 5189
Reputation: 186
thanks h brooker you helped me alot
for UWP users:
AppiumOptions options = new AppiumOptions();
options.PlatformName = "UWP";
options.AddAdditionalCapability("deviceName", "WindowsPC");
options.AddAdditionalCapability("app", AppId);
session = new WindowsDriver<WindowsElement>(new
Uri("http://127.0.0.1:4723"), options);
Upvotes: 1
Reputation: 246
I think the URI is creating an issue .. Try using URL like the following snippet..
URL url = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AppiumDriver<MobileElement>(url,cap);
Upvotes: 0
Reputation: 111
I worked this out. If anyone runs into this, the following initialisation works for me.
public void androidTest(){
AndroidDriver<AndroidElement> driver;
AppiumOptions options = new AppiumOptions();
options.PlatformName = "Android";
options.AddAdditionalCapability("deviceName", "MyDevice");
options.AddAdditionalCapability("platformVersion", "PlatformV");
options.AddAdditionalCapability("automationName", "UiAutomator2");
options.AddAdditionalCapability("appPackage", "MyPackage");
options.AddAdditionalCapability("appActivity", "MyActivity");
Uri url = new Uri("http://127.0.0.1:4723/wd/hub");
driver = new AndroidDriver<AndroidElement>(url, options);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
// Some example selectors
driver.FindElementByClassName("android.widget.EditText").SendKeys("test");
driver.FindElement(MobileBy.AndroidUIAutomator("new UiSelector().className(\"android.widget.EditText\").instance(1)")).SendKeys(Username);
}
Upvotes: 10