我找不到一篇可以在 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/