appium for mobile web 之使用 ChromeDriver
之前研究了一段时间的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的更多相关文章
- 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 ...
- front end about mobile web techs
WEB OF DEVICES http://www.w3.org/standards/webofdevices/ MOBILE WEB http://www.w3.org/standards/webd ...
- Mobile Web中URL设计问题
自己虽然也注册了CSDN账号,但是没有在上面发表过博客等内容.不过经常在Google里面搜索相关内容时,会显示csdn的结果.这也说明国内很多IT人员都会在CSDN发表博客,记录解决问题过程或者想法. ...
- swipe.js 2.0 轻量级框架实现mobile web 左右滑动
属性总结笔记如下: <style> .swipe { overflow: hidden; //隐藏溢出 清楚浮动 visibility: hidden; //规定元素不可见 (可以设置,当 ...
- Mobile Web调试工具Weinre (reproduce)
Mobile Web调试工具Weinre 现在.将来,用移动设备上网越来越成为主流.但对于开发者们来说,移动web的调试一直是个难题,前期可以使用模拟器来协助调试,但到了真机调试阶段就让人非常头痛.而 ...
- 打造离线使用的Mobile Web App
最近公司举办技术大赛,我和同事一起制作了一个叫做10K Hours的Mobile Web App,可以帮助你通过一万小时的努力,成为某个领域的专家.正好前段时间翻译了一本书<HTML5 Mobi ...
- 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 ...
- 开发库比较(3) - Mobile Web 开发 - Sencha, jquerymobiel, phonejs, jqtouch, jqmobi
我们一直坚信Html/css在界面上最终会一统江湖,因为在众多的界面编写中,qt,gtk,wpf,win form, wxwidgets等等,只有Html/CSS是真正拥有统一标准,只有这个有潜力作用 ...
- Lesson 3: The Amazing New Mobile Web
Lesson 3: The Amazing New Mobile Web Article 1: This is Responsive by Brad Frost 各种响应式网站设计的资源. Artic ...
随机推荐
- JS正则表达式进阶
贪婪量词 惰性量词 支配量词 描述--------------------------------------------------------- ...
- go 数组(array)、切片(slice)、map、结构体(struct)
一 数组(array) go语言中的数组是固定长度的.使用前必须指定数组长度. go语言中数组是值类型.如果将数组赋值给另一个数组或者方法中参数使用都是复制一份,方法中使用可以使用指针传递地址. 声明 ...
- cmd命令快速修改dns
新建cmd文件,修改红色ip部分,以 ANSI 编码保存,双击运行即可快速修改dns配置 netsh interface ip set dns "本地连接" source=stat ...
- 在ubuntu/deepin/mint等系统中使用命令删除文件或文件夹
此命令操作需谨慎: sudo rm -rf 文件夹路径(或文件路径)
- 【poj3875】 Lights
http://poj.org/problem?id=3875 (题目链接) 题意 有M个N位的不同的二进制数,他们异或起来前v位等于1,求这m个数的不同组合方式(同一组数不同顺序不算). Soluti ...
- Redis模式匹配删除key
Redis keys命令支持模式匹配,但是del命令不支持模式匹配,有时候需要根据一定的模式来模糊删除key,这时只能结合shell命令来完成了. 具体命令是: redis-cli KEYS &quo ...
- Alpha阶段测试报告
测试说明 APP中前后端交互的接口主要有两种,一种是游戏开始前获取信息的HTTP请求接口,这种接口可以看成是静态的,比较简单:另外一种就是游戏过程中进行实时通信的Websocket请求接口,因为这是在 ...
- Node实践之二
先从一个简单的demo说起,用cmd打开命令提示符,输入echo Hello,大家是不是看到终端上显示出了Hello字样,事实上这就是一个简单的事件. 回到正题,相信提到node.js,免不了让人想起 ...
- Raspberry Pi 3 --- GPIO control
Before input 'gpio readall', need install wiringPi download "wiringPi":git clone git://git ...
- centos ab命令安装
yum install apr-util -ymkdir abcd abyum -y install yum-utils -yyumdownloader httpd yum localinstall ...