如何将Appium与C#集成?

Arp*_*uch 10 c# specflow selenium-webdriver appium

我无法找到一个帖子,我可以用C#中的appium自动进行移动测试.

我在specflow中编写了我的网站自动化代码.我可以重复使用吗?

And*_*dry 9

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);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

你可以在我写的这篇文章中找到更多.


Arp*_*uch 8

最后到达解决方案在C#中运行测试.非常感谢安德里.

此解决方案在连接到计算机的手机的Chrome浏览器中运行网站:

使用Appium在Android设备上设置和运行C#程序的步骤和简短程序:

namespace poc
{
    using NUnit.Framework;    
    using System;
    using OpenQA.Selenium; 
    using OpenQA.Selenium.Appium;
    using OpenQA.Selenium.Appium.Interfaces;
    using OpenQA.Selenium.Appium.MultiTouch;
    using OpenQA.Selenium.Interactions;
    using OpenQA.Selenium.Remote;
    using OpenQA.Selenium.Appium.Android;

    [TestFixture()]
    public class TestAppium
    {
        public IWebDriver driver;

        [TestFixtureSetUp]
        public void SetUp()
        {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.SetCapability("device", "Android");
            capabilities.SetCapability("browserName", "chrome");
            capabilities.SetCapability("deviceName", "Motorola Moto g");
            capabilities.SetCapability("platformName", "Android");
            capabilities.SetCapability("platformVersion", "5.0.2");

             driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
        }  

        [Test()]
        public void OpenHofHomePage()
        {
            driver.Navigate().GoToUrl("http://YourWebsiteToTest.com");
            Assert.IsTrue(driver.Title.Equals("Your Website")," Sorry , the website didnt open!!");
        }

        [TestFixtureTearDown]
        public void End()
        {
            driver.Dispose();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

1)在C#中设置常用项目,使用NuGet包管理器安装Appium,Selenium,同样使用相同的进程安装Nunit.

2)下载Android SDK

3)Envrionment变量:添加变量名称"ANDROID_HOME"并在变量给出sdk文件夹的路径中,在PATH(在System变量中找到)中,将路径附加到sdk文件夹中的工具并追加到平台工具的路径.

4)连接你的设备(a.mobile设备的驱动程序应该安装在计算机中(安装我的案例moto g adb驱动程序)b.设备应该打开开发人员模式选项并检查调试器选项并且始终选中唤醒选项)

5)现在下载Appium并打开Appium.exe.

6)Appium窗口 - >在Android设置(第一个按钮)中,选中"使用浏览器"选项并选择"浏览器"作为选项.

7)启动appium节点服务器(顶部的播放按钮).

8)现在从视觉工作室进行测试,你会看到网站在手机浏览器中打开.