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

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

问题描述

我无法找到一个职位,我可以自动在C#appium移动测试。

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

我已经写在我的specflow网站自动化代码。我还可以重复使用吗?

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

推荐答案

Appium提供的 DOTNET-appium驱动这是您的API与appium接口。你可以用它来编写你的应用程序的自动化。

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

您可以找到更多的< A HREF =http://blogs.technet.com/b/antino/archive/2014/09/22/how-to-set-up-a-basic-working-appium-test-environment.aspx>此文章,我写的。

You can find more in this article I wrote.

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

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