用idea编写appium用例
来源:互联网 发布:windows文件恢复大师 编辑:程序博客网 时间:2024/06/07 12:56
1. 安装ContactManagers.spk:
路径apps/ContactManager/ContactManagers.spk
2. 打开用例到IntelliJ:
Open -- 选中appium/sample-code/examples/java/junit/pom.xml打开
3. 环境配置:
如果依赖的jar包没有加载进来,可能需要配置maven的路径
4. 运行测试用例:
右点选中AndroidContactsTest — Run'AndroidContactsTest'
用例欣赏:
package com.saucelabs.appium;import io.appium.java_client.AppiumDriver;import org.junit.After;import org.junit.Before;import org.junit.Test;import org.openqa.selenium.By;import org.openqa.selenium.WebElement;import org.openqa.selenium.remote.CapabilityType;import org.openqa.selenium.remote.DesiredCapabilities;import java.io.File;import java.net.URL;import java.util.List;public class AndroidContactsTest { private AppiumDriver driver; @Before public void setUp() throws Exception { // set up appium File classpathRoot = new File(System.getProperty("user.dir")); File appDir = new File(classpathRoot, "../../../apps/ContactManager"); File app = new File(appDir, "ContactManager.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("device","Android"); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability(CapabilityType.VERSION, "4.4"); capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability("app-package", "com.example.android.contactmanager"); capabilities.setCapability("app-activity", ".ContactManager"); driver = new AppiumDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities); } @After public void tearDown() throws Exception { driver.quit(); } @Test public void addContact(){ WebElement el = driver.findElement(By.name("Add Contact")); el.click(); List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText"); textFieldsList.get(0).sendKeys("Some Name"); textFieldsList.get(2).sendKeys("Some@example.com"); //driver.swipe(100, 500, 100, 100, 2); driver.findElementByName("Save").click(); }}
二. 新建自己的测试工程
步骤: New Project -- Maven -- 输入Project name -- Project location -- Next -- Next
加入pom依赖
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>LATEST</version> <scope>test</scope> </dependency> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>1.0.2</version> </dependency> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1</version> <scope>test</scope> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> <scope>test</scope> </dependency> <!-- Includes the Sauce JUnit helper libraries --> <dependency> <groupId>com.saucelabs</groupId> <artifactId>sauce_junit</artifactId> <version>1.0.18</version> <scope>test</scope> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.2.4</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> <repositories> <repository> <id>saucelabs-repository</id> <url>https://repository-saucelabs.forge.cloudbees.com/release</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
用例开始
package com.wirelessqa.android;import io.appium.java_client.AppiumDriver;import org.junit.After;import org.junit.Before;import org.junit.Test;import static org.junit.Assert.*;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.remote.CapabilityType;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.support.ui.ExpectedCondition;import org.openqa.selenium.support.ui.WebDriverWait;import java.io.File;import java.net.URL;import java.util.concurrent.TimeUnit;/** * Created by bixiaopeng on 14-5-13. */public class appium { private AppiumDriver driver; @Before public void setUp() throws Exception { File classpathroot = new File(System.getProperty("user.dir")); File appDir = new File(classpathroot, "apk"); File app = new File(appDir, "xiamimusic.apk"); System.out.print(app.getAbsolutePath()); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability(CapabilityType.VERSION, "4.4"); capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability("app-package", "fm.xiami.main"); capabilities.setCapability("app-activity", "fm.xiami.bmamba.activity.StartActivity"); driver = new AppiumDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities); } @Test public void login() throws Exception { //判断某个元素是否显示 if (driver.findElement(By.name("是否创建桌面快捷方式")).isDisplayed()) { driver.findElement(By.name("确定")).click(); } driver.findElement(By.name("我的音乐")).click(); driver.findElementByName("点击头像登录").click(); driver.findElementByName("虾米账户登录").click(); //输入字符 driver.findElementByName("输入邮箱地址").sendKeys("********"); //通过id查找 driver.findElement(By.id("fm.xiami.main:id/edit_password")).sendKeys("****"); driver.findElementById("fm.xiami.main:id/btn_login").click(); String userName = driver.findElementById("fm.xiami.main:id/user_name").getText(); //断言 assertEquals(userName, "老毕"); } @After public void tearDown() throws Exception { driver.quit(); }}
注意JDK版本的选择
Open Module Setting -- Language level: 5.0
微信公众帐号: wirelessqa
关于作者:
作者: 毕小朋 | 老 毕 邮箱: wirelessqa.me@gmail.com
微博: @WirelessQA 博客: http://blog.csdn.net/wirelessqa
0 0
- 用idea编写appium用例
- 用idea编写appium用例
- 用idea编写appium用例
- 用idea编写appium用例
- 使用python编写appium用例
- 使用python编写appium用例
- 移动端appium框架,编写用例,集成到jenkins上配置
- 利用 IDEA 编写 GUI
- Idea编写一个Servlet
- Idea编写webservice案例
- IDEA编写javaweb(1)
- Java语言基础系列之1--用IDEA编写HelloWorld
- idea+appium:如何选中、删除、修改文本框中的内容
- 用源码安装 appium
- appium
- Appium
- Appium
- Appium
- 贾巴尔:现役球员最爱邓肯 马刺打传统篮球太强大
- 软考小结
- 美国防部发布涉华军力报告 亮点不多自相矛盾
- oracle优化
- 分享一个中国领先的.Net论坛http://bbs.netluntan.com
- 用idea编写appium用例
- 浙江大华浙大2010年校园招聘笔试试题
- 链表类型list和foreard_list的特定容器算法
- 使用python编写appium用例
- ExtJs中Store简介(秘籍)
- Subsets II
- 利用cmd打开文件
- 《Javascript高级程序设计》第十三章——事件学习笔记(待续)
- ext中ArrayStore,JsonStore,XmlStore的用