mark~
赞赞赞!!! 最近正在思考这些东西呢!!!
现在 appium 支持 H5 了~定位 webview 内的元素妥妥的~至少我们的应用没问题~
二妹子!!!
还是喜欢 mybatis 多些
同 @shixue33 妹子的想法 想借助 django 不过具体的想法可能不一样 再说再说
private void consumeStatement() throws UiSelectorSyntaxException {
String statement;
int index = 0;
int parenCount = -1; // semicolons could appear inside String arguments, so we make sure we only count occurrences outside of a parenthesis pair
while (index < text.length()) {
if (text.charAt(index) == ';' && parenCount == 0) {
break;
}
if (text.charAt(index) == '(') {
if (parenCount < 0) {
parenCount = 1;
} else {
parenCount++;
}
}
if (text.charAt(index) == ')') {
parenCount--;
}
index++;
}
driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().index(0)"));
你把定位脚本传入得字符串放进去就知道了。
定义了一个 parenCount=-1 做标示;
遇到"(" -> parenCount=1
遇到")" -> parentCount--
所以 parenCount 最后肯定等于 0。
而传入的字符串是允许有 “;” 的,只不过只能放在分号外 (semicolons could appear inside String arguments, so we make sure we only count occurrences outside of a parenthesis pair)
所以也就是在解析字符串时,到了最后一个字符如果是";"就直接 break;如果不是那就 index++,最后也是不符合 while 条件跳出来的~
定位脚本
WebElement el = driver.findElementsByAndroidUIAutomator("new UiSelector().className(android.widget.ListView).childSelector(new UiSelector().className(android.widget.LinearLayout).clickable(true))");
打开 findElementByAndroidUIAutomator 方法
@SuppressWarnings("unchecked")
@Override
public RequiredElementType findElementByAndroidUIAutomator(String using) {
return (RequiredElementType) findElement("-android uiautomator", using);
}
protected WebElement findElement(String by, String using) {
if(using == null) {
throw new IllegalArgumentException("Cannot find elements when the selector is null.");
} else {
Response response = this.execute("findElement", ImmutableMap.of("using", by, "value", using));
Object value = response.getValue();
WebElement element;
try {
element = (WebElement)value;
} catch (ClassCastException var7) {
throw new WebDriverException("Returned value cannot be converted to WebElement: " + value, var7);
}
this.setFoundBy(this, element, by, using);
return element;
}
}
大概有点了解了 不过再底层一点的 就没看了
btw 楼主解析代码 一步步走 真好 很清晰呢 赞赞赞~
#49 楼 @laiyuncong8404
可以把 driver 的实例化封装在一个类方法内~(这是其中的一个方法而已)
不过如果后期希望做到不同设备不同 driver 跑同一份测试脚本(或者其他并发策略)就要另外对 driver 做其他处理(论坛内有不少帖子实现了并发的功能了)
#BasePage
//初始化driver
public AndroidDriver SetDriver() throws MalformedURLException {
try{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), this.SetCa());
}catch (MalformedURLException e){
e.printStackTrace();
}
return driver;
}
#DashPage
/**
* 业务封装
*/
//搜索 - 收藏
public void Search(String recipe,Class name) throws IOException, InvalidFormatException {
LoggerControler log = this.MyLogger(name);
AndroidDriver driver = super.SetDriver();
this.ClickSearchBox();
this.InputRecipe(recipe);
log.info("本次搜索的食材是:"+recipe);
driver.sendKeyEvent(66);
this.ClickCollectionItem();
//this.ClickFavorite();
log.info("收藏的菜谱名为:"+this.GetRecipeName());
super.captureScreen("Search_"+recipe);
Assert.assertTrue(GetRecipeName().contains(recipe));
log.info("该Case测试通过");
}
谢谢大家的回复和建议
#13 楼 @xushizhao 好的。等你的分享 ~
或许自己不应该考虑这么多的 性格问题伤不起
我表示很崇拜楼主。努力 ing
1.如果一个页面的同一个元素,在同一个 case 中, 不同时间做不同的操作,是写两个,还是定义两个,xml 解析成脚本时在做处理?
2.你们是用 UIautomator 把页面元素 dump 下来再去编辑修改维护 xml 吗?一个页面一个 xml。你们现在管理编辑起来感觉方便吗?
3.web 平台上显示的 html 点击运行开始解析脚本跑用例,这挺好的。以后你们的可以平台化了。
4.谢谢楼主的分享。
#47 楼 @louqqson008 appium 暂不支持哦~robotium 可以~appium 未来应该会支持~
#45 楼 @louqqson008 嗯。如果你觉得项目合适,可以用这种方式。不过我觉得 PO 不是最优方案。你可以了解下关键字。
赞赞赞 不懂 windowns 做热点可以设置吗