我使用在Mac机器上运行的Appium服务器和使用c#绑定的AppiumDriver从Windows机器执行测试。问题是,当我创建AndroidDriver的实例时,它的ctor会出现NullReferenceException。当我创建RemoteWebDriver的实例时,它可以顺利运行。这是我的代码:
var caps = new DesiredCapabilities();
caps.SetCapability(MobileCapabilityType.DeviceName, "Nexus_4");
caps.SetCapability("udid", "<valid-device-id>");
caps.SetCapability(MobileCapabilityType.App, "https://valid/path/to/my.apk");
caps.SetCapability(MobileCapabilityType.PlatformName, MobilePlatform.Android);
using (var drv = new AndroidDriver(ServerUri, caps)) // rises exception
//using (var drv = new RemoteWebDriver(ServerUri, caps)) // works smoothly
{
drv.GetScreenshot().SaveAsFile("Android.png", ImageFormat.Png);
}
例外:
System.NullReferenceException : Object reference not set to an instance of an object.
Result StackTrace:
at OpenQA.Selenium.Appium.AppiumDriver._AddAppiumCommands()
at OpenQA.Selenium.Appium.AppiumDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Appium.Android.AndroidDriver..ctor(Uri remoteAddress, DesiredCapabilities desiredCapabilities)
我哪里错了?为什么AndroidDriver的构造函数会提升此执行并且没有指定原因?