android程序与数据分离,使用 appium 做自动化测试如何做到程序和数据分离?

这个问题我已经解决了,现在把实现的代码展现一下,希望能帮助到大家,如果大家有更好的方法希望不吝赐教!

import io.appium.java_client.TouchAction;

import io.appium.java_client.android.AndroidDriver;

import java.util.Set;

import org.openqa.selenium.WebElement;

import org.testng.annotations.Test;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.InputStream;

import jxl.Cell;

import jxl.Sheet;

import jxl.Workbook;

public class leizhong {

public AndroidDriver driver;

public leizhong(AndroidDriver driver){

this.driver=driver;

}

@Test

public void swpie() throws Exception{

//获取当前的混合应用类型,判断如果是 webview 跳转进入 webview

Set contextNames = driver.getContextHandles();

for(String contextName : contextNames){

System.out.println(contextName);

if(contextName.contains("WEBVIEW")){

driver=(AndroidDriver) driver.context(contextName);

}else{

System.out.println("no WEBVIEW");

}

}

Thread.sleep(2000);

driver=(AndroidDriver) driver.context("NATIVE_APP");

WebElement loginBtn=driver.findElementByName("社区");

loginBtn.click();

Thread.sleep(20000);

System.out.println("社区");

Thread.sleep(2000);

WebElement loginBtn1=driver.findElementByName("糖友锻炼");

loginBtn1.click();

System.out.println("糖友锻炼");;

Thread.sleep(2000);

try{

File file = new File("d:\test.xls");

InputStream in = new FileInputStream(file);

Workbook workbook = Workbook.getWorkbook(in);

Sheet sheet = workbook.getSheet(0);

int rowLength=sheet.getRows();

System.out.println(rowLength);

for(int i=1;i

Thread.sleep(3000);

driver.findElementByXPath("//android.widget.ImageView[contains(@index,2)]").click();

Thread.sleep(2000);

WebElement title=driver.findElementByName("最多 30 个字");

Cell c10=sheet.getCell(0,i);

String strc10=c10.getContents();

System.out.println(strc10);

title.sendKeys(strc10);

Thread.sleep(20000);

Cell c21=sheet.getCell(1,i);

String strc21=c21.getContents();

System.out.println(strc21);

driver.findElementById("com.qshealthcare.qshc:id/activity_publish_new_main_title_content_et").sendKeys(strc21);

Thread.sleep(2000);

driver.findElementByName("发布").click();

Thread.sleep(1000);

}

}catch(Exception e){

System.out.println("failed!");

}

System.out.println("success");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值