首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Appium与C#集成?

如何将Appium与C#集成?
EN

Stack Overflow用户
提问于 2015-02-20 20:41:58
回答 4查看 25.6K关注 0票数 11

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

我已经写了我的网站自动化代码在specflow中。我也可以重用它吗?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-02-21 16:56:15

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

这里没有提供任何示例,也没有提供代码,所以我不能真正地向您展示一些东西。我将写下一些C#代码,让您了解如何在C#中编写一个简单的测试:

代码语言:javascript
复制
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);
    }
  }
}

你可以在这篇文章上找到更多我写的。

票数 11
EN

Stack Overflow用户

发布于 2015-02-22 22:07:22

最终到达了解决方案,在C#中运行了一个测试。非常感谢Andry.

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

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

代码语言:javascript
复制
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();
        }
    }
}

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

2)下载Android

3)环境变量:将变量名"ANDROID_HOME“和变量给予路径添加到sdk文件夹、路径(在系统变量中找到)、将路径添加到sdk文件夹中的工具和将路径附加到平台工具中。

4)连接您的设备(a.mobile设备的驱动程序应该安装在计算机中(我的情况是安装了moto g亚行驱动程序)。设备应该启用开发人员模式选项,并检查调试器选项和始终保持清醒选项。

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

6)安卓环境下的Appium窗口-> (第一个按钮),选中“使用浏览器”选项,选择“浏览器”作为选项。

7)启动appium节点服务器(在顶部按下按钮)。

8)现在从visual studio运行测试,您将在电话浏览器中看到网站打开。

票数 8
EN

Stack Overflow用户

发布于 2015-03-03 14:15:05

为了使这个更全面,我写了一篇博文,用图片清楚地解释了所有的步骤。这是一个逐步教程使用appium与c#和MSTest,您可以在这里阅读。http://www.binaryclips.com/2016/03/test-automation-on-android-using-appium.html

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28637796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档