您的位置:首页 > 移动开发

mac下appium自动化测试安卓环境的搭建和运行测试

2015-05-28 10:14 696 查看
1 appium的安装在博客/article/4851525.html里讲的很好很详细,是通过命令行安装的,

也可以下载安装包安装

2启动appium

➜ ~ appium

info: Welcome to Appium v1.4.1 (REV ce6220829063679bcccf5724515c29569c4a16d9)

info: Appium REST http interface listener started on 0.0.0.0:4723

info: Console LogLevel: debug

3 启动安卓模拟器



4在eclipse中建立maven项目,pom如下

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.syb</groupId>
<artifactId>testproject</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>testproject Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.webdriver</groupId>
<artifactId>webdriver-selenium</artifactId>
<version>0.9.7376</version>
</dependency>
</dependencies>
<build>
<finalName>testproject</finalName>
</build>
</project>


5,java代码为,这里只是找到两个按钮进行点击,并打印按钮的text,运行后可以看到模拟器中程序会自动打开进行点击测试,并在控制台输出

public class AppiumTest {
private static AppiumDriver driver;
public static void main(String[] args) throws  Exception{
//配置webdriver
// set up appium against a local application
File appDir = new File(System.getProperty("user.dir"));
File app = new File(appDir, "app-release.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName","emulator-5554");
// capabilities.setCapability("device", "Selendroid");
// capabilities.setCapability("automationName", "Selendroid");
capabilities.setCapability("platformVersion", "4.1.1");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.example.fragmentdemo");
capabilities.setCapability("appActivity", ".MainActivity");
//appium的独特地方,使用自己的AppiumDriver, 它本身是继承自WebDriver
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities) {
@Override
public MobileElement scrollTo(String s) {
return null;
}

@Override
public MobileElement scrollToExact(String s) {
return null;
}
};
//设置超时
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println(driver.getAppStrings());
WebElement ele = driver.findElementById("news_text");
System.out.println(ele.getText());
ele.click();
Thread.currentThread().sleep(2000);
WebElement ele2 = driver.findElementById("contacts_text");
System.out.println(ele2.getText());
ele2.click();
driver.quit();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: