Appium总结

转自:http://blog.csdn.net/jiguanghoverli/article/details/17916351
 
  今天使用appium来测试android客户端,使用的是selenium + webdriver+java,发现客户端的引导页无法操作,搜索到内容如下:
1. 滚动条的滑动(http://www.cnblogs.com/nova/articles/1091993.html)
    top=document.documentElement.scrollTop;
    left=document.documentElement.scrollLeft;  
例如:
        String setscroll ="document.documentElement.scrollTop=" + height;              
        JavascriptExecutor jse=(JavascriptExecutor)driver;  
        jse.executeScript(setscroll); 
2. 向下滑动一页
Actions actions = new Actions(driver);
actions.sendKeys(Keys.BACK_SPACE).perform();
3:鼠标滑动
element =driver.findElement(By.cssSelector(".user-info.right>div>p>a"));
Actions builder = new Actions(driver);
builder.moveToElement(element).build().perform();
//Thread.sleep(100); no need
element = driver.findElement(By.cssSelector(".frd-del"));
element.click();
4:加载ua
private static WebDriver driver;
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override",
      "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341Safari/528.16");
driver = new FirefoxDriver(profile);
5:页面切换
String pWindUrl = driver.getCurrentUrl();
//跳至新打开的窗口
if (driver.getWindowHandles().size() != 2) {fail(); }
for (String handle : driver.getWindowHandles()) {
    driver.switchTo().window(handle);
    if(driver.getCurrentUrl().equals(pWindUrl)){
      driver.close(); //关闭父窗口
    } else {
            //6张图片
            if(driver.findElements(By.cssSelector(".img")).size() != 6) { fail();}
    }
}
6:alert提示
private Alert alert;
alert = driver.switchTo().alert();
alert.accept();
//alert.dismiss();
7:截屏
try {
      FilescrFile = ((TakesScreenshot) driver)
                  .getScreenshotAs(OutputType.FILE);
      FileUtils.copyFile(scrFile, new File("img\\Screenshot.png"));
} catch (Exception e) {
      e.printStackTrace();
} finally {
      //driver.close();
}
8.查找当前页面的编辑区域
textfields = driver.find_elements_by_tag_name("textfield")
els=driver.find_elements_by_tag_name("text")
9.查找元素
table =driver.find_element_by_tag_name("tableView")
row = table.find_elements_by_tag_name("tableCell")[index]
rows = table.find_elements_by_tag_name("tableCell")
nav_bar = driver.find_element_by_tag_name("navigationBar")
scroll = driver.find_element_by_tag_name("scrollview")
webview = scroll.find_element_by_tag_name("webview")
#find the URL field
textfield = driver.find_element_by_name("URL entry")
# get the window handles (webview)
handle = self.driver.window_handles[0]
self.driver.switch_to_window(handle)
# Find the google logo
logo = self.driver.find_element_by_id("hplogo")
driver.execute_script("mobile: leaveWebView")
# make screenshot and save it to the local filesystem
success = self.driver.get_screenshot_as_file("foo.png")
10:执行脚本_Java
Map tap = new HashMap();  
tap.put("tapCount", new Double(2));
tap.put("touchCount", new Double(1));  
tap.put("duration", new Double(0.5));  
tap.put("x", new Double(300));  
tap.put("y", new Double(300));  
driver.executeScript("mobile: tap", tap); 
Python:
driver.execute_script("mobile: tap", {"touchCount":"1", "x":"0.9","y":"0.8", "element":element.id})
滑动引导图从第一张到第二张( http://testerhome.com/topics/401)
try:
    swipe_args = { 'startX':0.9,'startY':0.5, 'endX':0.1, 'endY':0.5, 'duration':10}
    self.driver.execute_script("mobile: swipe", swipe_args)
except Exception, e:
    print e
请参考:https://github.com/appium/appium/blob/master/docs/gestures.md
11.根据路径获取元素
self.driver.find_elements_by_xpath("//ImageView")
self.driver.find_elements_by_xpath("//TextView")
12.点击屏幕的某个点
self.driver.execute_script("mobile: tap", {"touchCount":"1","x":22, "y":45}) #点击屏幕坐标为(22,45)的点1次
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值