之前研究了一段时间的appium for native app 相应的总结如下:

                                              appium测试环境搭建 :http://www.cnblogs.com/tobecrazy/p/4562199.html

                    知乎Android客户端登陆:http://www.cnblogs.com/tobecrazy/p/4579631.html

appium实现截图和清空EditText:http://www.cnblogs.com/tobecrazy/p/4592405.html

appium 滑动处理:http://www.cnblogs.com/tobecrazy/p/4612133.html

最近有人问我怎么使用web driver,所以特来研究一下

准备工作:1. 安装chrome

编写代码

package com.dbyl.core;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import io.appium.java_client.android.AndroidDriver; import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit; public class baidu {
AndroidDriver<WebElement> driver; /**
* @author Young
* @throws IOException
*/
public void startRecord() throws IOException {
Runtime rt = Runtime.getRuntime();
// this code for record the screen of your device
rt.exec("cmd.exe /C adb shell screenrecord /sdcard/runCase.mp4"); } @BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
// set up appium DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("platformVersion", "4.4");
driver = new AndroidDriver<WebElement>(new URL(
"http://127.0.0.1:4723/wd/hub"), capabilities);
startRecord(); } @Test
public void runChromeWebBrowser() {
driver.get("http://www.baidu.com");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
System.out.println(driver.getTitle());
snapshot((TakesScreenshot) driver, "before_search.png");
driver.findElementByXPath("//textarea[@id='index-kw']").sendKeys(
"appium");
driver.findElement(By.xpath("//button[@id='index-bn']")).click();
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
System.out.println(driver.getTitle());
snapshot((TakesScreenshot) driver, "after_search.png");
Assert.assertTrue(driver.getTitle().contains("appium")); } /**
* This Method create for take screenshot
*
* @author Young
* @param drivername
* @param filename
*/
public static void snapshot(TakesScreenshot drivername, String filename) {
// this method will take screen shot ,require two parameters ,one is
// driver name, another is file name String currentPath = System.getProperty("user.dir"); // get current work
// folder
File scrFile = drivername.getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy
// somewhere
try {
System.out.println("save snapshot path is:" + currentPath + "/"
+ filename);
FileUtils
.copyFile(scrFile, new File(currentPath + "\\" + filename));
} catch (IOException e) {
System.out.println("Can't save screenshot");
e.printStackTrace();
} finally {
System.out.println("screen shot finished, it's in " + currentPath
+ " folder");
}
} @AfterClass
public void afterTestStopDriver() {
driver.quit();
}
}

这其中,遇到输入框识别的问题,刚开始是使用UIAutomator

发现 web 的element 压根识别不了,最后想到这应该和selenium webdriver一样

所以在识别百度输入框,By xpath

"//textarea[@id='index-kw']"

appium for mobile web 之使用 ChromeDriver的更多相关文章

  1. appium(4)-Automating mobile web apps

    Automating mobile web apps If you’re interested in automating your web app in Mobile Safari on iOS o ...

  2. front end about mobile web techs

    WEB OF DEVICES http://www.w3.org/standards/webofdevices/ MOBILE WEB http://www.w3.org/standards/webd ...

  3. Mobile Web中URL设计问题

    自己虽然也注册了CSDN账号,但是没有在上面发表过博客等内容.不过经常在Google里面搜索相关内容时,会显示csdn的结果.这也说明国内很多IT人员都会在CSDN发表博客,记录解决问题过程或者想法. ...

  4. swipe.js 2.0 轻量级框架实现mobile web 左右滑动

    属性总结笔记如下: <style> .swipe { overflow: hidden; //隐藏溢出 清楚浮动 visibility: hidden; //规定元素不可见 (可以设置,当 ...

  5. Mobile Web调试工具Weinre (reproduce)

    Mobile Web调试工具Weinre 现在.将来,用移动设备上网越来越成为主流.但对于开发者们来说,移动web的调试一直是个难题,前期可以使用模拟器来协助调试,但到了真机调试阶段就让人非常头痛.而 ...

  6. 打造离线使用的Mobile Web App

    最近公司举办技术大赛,我和同事一起制作了一个叫做10K Hours的Mobile Web App,可以帮助你通过一万小时的努力,成为某个领域的专家.正好前段时间翻译了一本书<HTML5 Mobi ...

  7. Introducing the Accelerated Mobile Pages Project, for a faster, open mobile web

    https://googleblog.blogspot.com/2015/10/introducing-accelerated-mobile-pages.html October 7, 2015 Sm ...

  8. 开发库比较(3) - Mobile Web 开发 - Sencha, jquerymobiel, phonejs, jqtouch, jqmobi

    我们一直坚信Html/css在界面上最终会一统江湖,因为在众多的界面编写中,qt,gtk,wpf,win form, wxwidgets等等,只有Html/CSS是真正拥有统一标准,只有这个有潜力作用 ...

  9. Lesson 3: The Amazing New Mobile Web

    Lesson 3: The Amazing New Mobile Web Article 1: This is Responsive by Brad Frost 各种响应式网站设计的资源. Artic ...

随机推荐

  1. ajax 请求另一个html页面的指定的一部分 加载到本页面div

    $.ajax( { url: url, //这里是静态页的地址 type: "GET", //静态页用get方法,否则服务器会抛出405错误 success: function(d ...

  2. js(jQuery)获取时间的方法及常用时间类

    获取JavaScript 的时间使用内置的Date函数完成 var mydate = new Date();mydate.getYear(); //获取当前年份(2位)mydate.getFullYe ...

  3. JSP基础学习

    JQuery教程: http://www.w3school.com.cn/jquery/ HTTP协议的 http://www.w3.org/Protocols/rfc2616/rfc2616.htm ...

  4. Windows Live Writer 2012 on .net 4

    众所周知,强大的live套件不再更新,止步于2012,所以安装的时候需要.net 3.5的运行时,这很讨厌,在新系统里面是.net 4运行时的,.net运行时的设计者脑袋张虫,新的居然不默认支持旧的程 ...

  5. linux基础知识与技能1

    1.隐藏文件与非隐藏文件Linux中:linux中隐藏文件特点是文件名以.开头,跟文件属性无关.在linux中查看隐藏文件用ls -a命令(普通显示ls)2.相对路径与绝对路径什么是路径:路径是用来标 ...

  6. hibernate通过xml配置文件实现表与实体的映射

    这里讨论的是一对多的关系 在做公交卡系统,会涉及到两张表,忽略两种表的作用,只关心他们之间的关系 : 卡规格表和卡类表,一种卡规格会对应多个卡类 实体类: /** * 卡类型表的实体 */ publi ...

  7. Android只能动态注册的广播Action

    只能动态注册的广播(部分): android.intent.action.SCREEN_ON android.intent.action.SCREEN_OFF android.intent.actio ...

  8. bzoj 4553 && HEOI2016 day1t3 seq

    一个序列在所有变换中都单调不降的条件是i<j,a[i]<=min[j],mx[i]<=a[j],所以套CDQ就行了. #include<iostream> #includ ...

  9. Leetcode 285. Inorder Successor in BST

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST. 本题 ...

  10. Jsoup提取文本时保留标签

    使用Jsoup来对html进行处理比较方便,你可能会用它来提取文本或清理html标签.如果你想提取文本时保留标签,可以使用Jsoup.clean方法,参数为html及标签白名单: Jsoup.clea ...