【发布时间】:2023-03-24 18:05:01
【问题描述】:
我正在尝试使用 Appium 对在 Windows 10 上以 chrome 运行的 Web 应用程序进行自动化测试。 我有如下代码,使用 chromedriver 可以很好地工作。我想将此移至基于 appium 的方法。
RemoteWebDriver driver = new ChromeDriver(@"C:\Users\Administrator\Downloads\chromedriver_win32");
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(60));
driver.Url = "https://www.bing.com/";
RemoteWebElement element = (RemoteWebElement)driver.FindElementById("sb_form_q");
element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
wait.Until(x => x.Title.Contains("webdriver"));
我在互联网上搜索并找到了很多代码来在 Windows 设备上的 android 模拟器上测试 chrome 上的 web 应用程序。我没有找到任何直接在 Windows 10 上运行 chrome 浏览器的示例。 根据我的理解,我尝试通过更改所需功能来采用代码,如下所示。
DesiredCapabilities caps = DesiredCapabilities.Chrome();
caps.SetCapability(CapabilityType.BrowserName, "chrome");
caps.SetCapability(CapabilityType.Version, "60");
caps.SetCapability(CapabilityType.Platform, "Windows 10");
caps.SetCapability("platformName", "Windows");
//caps.SetCapability("app", @"C:\Users\Administrator\Downloads\chromedriver_win32\Chromedriver.exe");
caps.SetCapability("app", @"Chrome");
caps.SetCapability("deviceName", "WindowsPC");
driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4725/wd/hub"), caps, TimeSpan.FromSeconds(60));
driver.Url = "https://www.bing.com/";
((IWebDriver)driver).Navigate().GoToUrl("https://www.bing.com/");
RemoteWebElement element = (RemoteWebElement)driver.FindElementById("sb_form_q");
element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
Thread.Sleep(5000);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
wait.Until(x => x.Title.Contains("webdriver"));
但这不起作用。 我认为问题在于我无法弄清楚如何设置所需的功能,以便在http://127.0.0.1:4725/wd/hub 上运行的 appium 服务能够启动 chromedriver 并运行测试。
有人可以帮忙指出上述代码的错误吗? 感谢您的帮助。
【问题讨论】:
标签: c# windows automated-tests appium