1.简单的Python脚本
Launch后,执行脚本
#coding:utf-8
importunittestimportosfrom selenium importwebdriverfrom time importsleepclassDttest(unittest.TestCase):defsetUp(self):
self.driver=webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities={'platformName': 'iOS','deviceName':'iPhone 5s'})deftearDown(self):
self.driver.quit()deftest_test(self):
sleep(10)
由于Appium中的iOS Settings中BundleID还有设备的UDID都已经填写好,所以脚本中就没有重复填写
需要注意的是:这里的command_executor要和Appium中的Server Address一致,不然怎么可能连得上。、
Ps:deviceName也是必填的,但是发现name填错了也没有任何事情发生
tearDown中是用例执行结束后执行的操作
test_test是具体的测试用例,先用一个sleep代替下,后面改成具体的操作加断言
2.元素的属性设置
个人觉得基于UI的自动化,首先最重要的是要找到你想找的元素,然后你才能对元素进行操作并对结果进行断言
以app中的分数为例,如果没有设置ID的话,只能通过xpath进行定位
设置了元素的name属性后可以通过find_element_by_name("scoreLab")进行定位,这样找错元素的几率也会变小很多
所以这个name属性在哪里设置呢。、
这里就要麻烦我们的开发了
在storyboard中的Accessibility中加上Identifier属性
Label对应的是元素的value值
以前遇到的坑:
static text的value无法进行获取,会和name的属性一致
在UILabel category中添加如下代码可以实现获取value属性
@interface UIViewController (WarninigBar)
- (void)showTopWarning:(NSString *)warningText;
@end
@interface UILabel (MyAccessibility)
@property(nonatomic, copy) NSString *accessibilityValue;
@end
@implementation UILabel (MyAccessibility)
@dynamic accessibilityValue;
-(NSString *)accessibilityValue {
// Here we force UIKit to return Label value, not the accessibility label
return self.text;
}
@end