我正在使用 Appium 和 c# 在 Android 真实设备上自动化移动 Web 测试。 我已经看到Java中有get方法可以导航到给定的URL,例如:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setPlatform(Platform.ANDROID);
capabilities.setCapability("device", "android");
capabilities.setCapability("app", "chrome");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get("http://www.google.com");
System.out.println("Android Title is: " + driver.getTitle())
我在appium dot net driver中找不到这样的方法。 是我的错误还是没有这样的方法? 那么最好的导航方式是什么?
这是我使用的 C# 代码:
[TestClass]
public class UnitTest1
{
private DesiredCapabilities _capabilities;
private AndroidDriver _driver;
public void InitializeDriver()
{
Console.WriteLine("Connecting to Appium server");
_capabilities = new DesiredCapabilities();
_capabilities.SetCapability("deviceName", "Nexus One");
_capabilities.SetCapability("newCommandTimeout", "300");
_capabilities.SetCapability(CapabilityType.BrowserName, "Chrome");
_capabilities.SetCapability(CapabilityType.Version, "5.0.1");
_capabilities.SetCapability(CapabilityType.Platform, "Android");
//Application path and configurations
_driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), _capabilities);
}
没有 _driver.Get() 或 _driver.SendKeys。我应该用什么?
试试这个:
driver.sendKeys(URL);
可以通过对象浏览器找到答案(这就是我所做的)。 Java 代码的模拟如下所示:
_navigation = _driver.Navigate();
_navigation.GoToUrl(@"http://stackoverflow.com");
所以完整的列表将变成这样:
public void InitializeDriver()
{
Console.WriteLine("Connecting to Appium server");
_capabilities = new DesiredCapabilities();
_capabilities.SetCapability("deviceName", "Nexus One");
_capabilities.SetCapability("newCommandTimeout", "300");
_capabilities.SetCapability(CapabilityType.BrowserName, "Browser");
_capabilities.SetCapability(CapabilityType.Version, "5.0.1");
_capabilities.SetCapability(CapabilityType.Platform, "Android");
//Application path and configurations
_driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), _capabilities);
_navigation = _driver.Navigate();
_navigation.GoToUrl(@"http://stackoverflow.com");
}
使用: driver.navigate().to("http://url.to");