如何使用appium(c#)

时间:2015-10-26 22:19:57

标签: ios appium

您好我在ios上自动化本机ios应用程序。我已经自动化了原生应用程序,但是为了在Windows上运行的c#代码在mac上启动appium服务器,我需要知道如何为ios平台设置所需的功能。

2 个答案:

答案 0 :(得分:2)

请找到以下c#语言代码的和平:

 DesiredCapabilities capabilities = new DesiredCapabilities();
 TestCapabilities testCapabilities = new TestCapabilities();

  testCapabilities.App = "";
  testCapabilities.AutoWebView = true;
  testCapabilities.AutomationName = "";
  testCapabilities.BrowserName = String.Empty; // Leave empty otherwise you test on browsers
  testCapabilities.DeviceName = "Needed if testing on IOS on a specific device. This will be the UDID";
  testCapabilities.Platform = TestCapabilities.DevicePlatform.IOS; // Or Android
  testCapabilities.PlatformVersion = String.Empty; // Not really needed

  testCapabilities.AssignAppiumCapabilities(ref capabilities);
  driver = new AppiumDriver(testServerAddress, capabilities, INIT_TIMEOUT_SEC);
  driver.Manage().Timeouts().ImplicitlyWait(IMPLICIT_TIMEOUT_SEC);

答案 1 :(得分:0)

要在iOS模拟器/真实设备上运行Appium测试,需要Mac硬件,并且要在真实设备上运行测试,还需要来自Apple开发人员帐户的团队ID。更多详细信息here

通过电缆将iPhone连接到MacOS,或者将iPhone和Mac计算机都连接到相同的无线网络(WiFi)。

用于初始化appium iOS驱动程序以在真实设备上运行测试的C#代码:

//Initialise driver options
AppiumOptions capabilities = new AppiumOptions();

//Declare capabilities
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "iOS");
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "13.2"); //put real device iOS version
capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "iPhone X"; //put real device name
capabilities.AddAdditionalCapability(MobileCapabilityType.AutomationName, "XCUITest");

if (appInstalled)
{
    //if app is installed and don't want to re-install, use below capability
    capabilities.AddAdditionalCapability(IOSMobileCapabilityType.BundleId, "<app-bundle-id>");
}

else
{
    //(re)installs app
    capabilities.AddAdditionalCapability(IOSMobileCapabilityType.AppName, "<name-of-test-app>");
    capabilities.AddAdditionalCapability(MobileCapabilityType.App, "<absolute-path-to-test-app.app>");
}

capabilities.AddAdditionalCapability(MobileCapabilityType.Udid, "<real-device-Udid>");
capabilities.AddAdditionalCapability("xcodeOrgId", "<team-id>");
capabilities.AddAdditionalCapability("xcodeSigningId","iPhone Developer");

//Initialise iOS driver
var driver = new IOSDriver<IMobileElement<AppiumWebElement>>(capabilities);