c# - 如何将Appium与C#集成?

标签 c# selenium-webdriver appium specflow

我找不到一篇可以在 C# 中使用 appium 自动化移动测试的帖子。

我已经在规范流中编写了我的网站自动化代码。我也可以重复使用它吗?

最佳答案

Appium 提供 dotnet-appium-driver这是与 Appium 交互的 API。您可以使用它来编写应用程序自动化。

您在这里没有提供任何示例,也没有提供代码,因此我无法真正采取行动向您展示。我将写一些 C# 代码,让您了解如何用 C# 编写简单的测试:

namespace AppiumTests
{
  using System;
  // .NET unit test namespaces needed here as well, just not mentioning them
  using OpenQA.Selenium; /* Appium is based on Selenium, we need to include it */
  using OpenQA.Selenium.Appium; /* This is Appium */

  [TestClass]
  public class TestSuite
  {
    private AppiumDriver 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 testCapabilities = new DesiredCapabilities();

      testCapabilities.App = "<your-app-file>";
      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.FwkVersion = "1.0"; // Not really needed
      testCapabilities.Platform = TestCapabilities.DevicePlatform.Android; // Or IOS
      testCapabilities.PlatformVersion = String.Empty; // Not really needed

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

    [TestCleanup]
    public void AfterAll()
    {
      driver.Quit(); // Always quit, if you don't, next test session will fail
    }

    /// 
    /// Just a simple test to heck out Appium environment.
    /// 
    [TestMethod]
    public void CheckTestEnvironment()
    {
      var context = driver.GetContext();
      Assert.IsNotNull(context);
    }
  }
}

您可以在 this article 中找到更多信息我写的。

关于c# - 如何将Appium与C#集成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28637796/

相关文章:

java - 即使在运行配置中指定,Eclipse 也无法找到 adb

c# - 在将日期时间插入 SQL Server 数据库之前验证日期时间

c# - ClickOnce 部署中的 Crystal Reports

c# - 如何检测 BindingList<T> 中项目属性的更改?

python-3.x - 如何使用 Selenium 和 Python 登录 reddit

ruby - Selenium 滚动元素进入(中心) View

google-chrome - 使用 selenium webdriver 发布打开 chrome - 没有互联网连接

flutter - 我们如何向 Flutter 小部件添加选择器/id,以便可以从 Appium 访问它们

c# - 自定义错误页面中的 AspxErrorPath

java - UI Automator 将屏幕截图作为纵向而不是横向