拥有以下代码:
[TestClass]
public class RepairMobileTests
{
public AppiumDriver driver;
public DesiredCapabilities capabilities;
[TestInitialize]
public void BeforeAll()
{
capabilities = new DesiredCapabilities();
capabilities.SetCapability("device", "Android");
capabilities.SetCapability(CapabilityType.Platform, "WINDOWS");
capabilities.SetCapability(CapabilityType.BrowserName, "Chrome");
capabilities.SetCapability("deviceName", ConfigurationManager.AppSettings["deviceName"]);
capabilities.SetCapability("platformName", ConfigurationManager.AppSettings["platformName"]);
capabilities.SetCapability("platformVersion", ConfigurationManager.AppSettings["platformVersion"]);
capabilities.SetCapability("appPackage", ConfigurationManager.AppSettings["appPackage"]);
capabilities.SetCapability("appActivity", ConfigurationManager.AppSettings["appActivity"]);
capabilities.SetCapability("capability.policy.strict.Window.confirm", "noAccess");
}
[TestCleanup]
public void AfterAll()
{
driver.Quit();
}
[TestMethod]
public void LoginSuccessful()
{
WaitMethods wm = new WaitMethods();
driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
string homepage = "http://www.siteundertest.com/";
string username = "user";
string password = "pass";
ProdemandLoginPage pdl = new ProdemandLoginPage();
pdl.openPage(homepage, driver);
//Thread.Sleep(10000);
wm.WaitForAjax(driver);
driver.HideKeyboard(); // here is thrown the error
}
}
抛出错误:
Test Name: SearchMenu
Test FullName: RepairMobileTestAutomation.RepairMobileTests.SearchMenu
Test Source: c:\Users\net\Documents\Visual Studio 2013\Projects\RepairMobileTestAutomation\RepairMobileTestAutomation\RepairMobileTests.cs : line 419
Test Outcome: Failed
Test Duration: 0:00:19.5419473
Result Message:
Test method RepairMobileTestAutomation.RepairMobileTests.SearchMenu threw exception:
OpenQA.Selenium.WebDriverException: Unexpected error. unknown command: session/0a3e8c760809af9316358a5afa458541/appium/device/hide_keyboard
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Appium.AppiumDriver.HideKeyboard(String strategy, String key)
at OpenQA.Selenium.Appium.AppiumDriver.HideKeyboard()
at RepairMobileTestAutomation.RepairMobileTests.SearchMenu() in c:\Users\net\Documents\Visual Studio 2013\Projects\RepairMobileTestAutomation\RepairMobileTestAutomation\RepairMobileTests.cs:line 437
Appium日志在这里http://pastebin.com/4jdJLnY8 我在真实设备上运行测试,但我在Touch,Swipe,锁定设备,隐藏键盘和其他手势方面存在多个问题。如何触发点击或向下滚动等事件?有人可以发一个例子吗?我也试图旋转屏幕但没有任何反应。有没有办法做到这一点?我正在运行安装在设备上的Chrome应用上进行测试。
答案 0 :(得分:0)
如果您使用Android,您可以使用 self.driver.back()命令使用Appium隐藏键盘,我使用python,我通过Softkeyboard输入密钥后使用以下代码并关闭键盘并显示隐藏在键盘下方的项目
def test_sign_in_old(self):
self.driver.implicitly_wait(10)
print('Checking Already registered user')
self.driver.find_element_by_name("I'M A MEMBER").click()
self.driver.find_element_by_id('com.XXX.android:id/m_emailTextField').send_keys('xxx@gmail.com')
self.driver.find_element_by_id('com.XXX.android:id/m_passwordTextField').send_keys("1234abcd")
self.driver.back()
self.driver.implicitly_wait(5)