如何将 Appium 与 C# 集成? [英] How to integrate Appium with C#?

查看:39
本文介绍了如何将 Appium 与 C# 集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am unable to find a single post where i can automate mobile testing with appium in C#.

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

I have written my Website automation code in the specflow. Can I also Reuse it ?

推荐答案

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

Appium provides the dotnet-appium-driver which is your API to interface with Appium. You can use that to write your app automation.

您在此处未提供任何示例或代码,因此我无法真正采取行动向您展示.我将只写一些 C# 代码,让您了解如何在 C# 中编写简单的测试:

You did not provide any example here nor code, so I cannot really act on something to show you. I will just write down some C# code to let you understand how a simple test in C# can be written:

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);
    }
  }
}

您可以在 这篇文章 我写的.

这篇关于如何将 Appium 与 C# 集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆