首页 文章 精选 留言 我的

精选列表

搜索[原生UI],共10000篇文章
优秀的个人博客,低调大师

Appium Android UI自动化简介 + 实战

一、自动化比较适合的场景 1、稳定迭代; 2、回归阶段;回归上一版功能,对新功能不适用。 3、研发驱动的底层代码重构; 不适合case:无网、支付、需要数据准备的case 二、Appium简介 Appium是目前最为强大的自动化测试框架,支持IOS 与Android。 IOS: 苹果公司的 UIAutomation。 Android 4.2+: Google公司的 UiAutomator。 Android 2.3+: Google公司的 Instrumentation. (Instrumentation 的支持是通过绑定另外一个独立的Selendroid项目来实现的)。 C/S 架构 Appium的核心是一个遵守REST设计风格的web 服务器,它接受客户端的连接,接收客户端的命令,在手机设备上执行命令,然后通过HTTP的响应收集命令执行的结果。 支持多语言 三、case编写思路 过程抽象: 定位-------操作-------等待---------校验---------定位 定位方式 1、文案 2、id 3、xpath 4、类名 5、属性 6、组合 PS:元素信息通过UIAutomator Viewer工具查看: 操作 1、点击;2、输入;3、滑动; 等待、判断页面元素出现或者消失: 1、 sleep 2、 View或文案显示 3、 View或文案消失 校验 按需求~文案显示或消失,View显示或消失,Dialog消失或消失,Toast等等 四、操作步骤 1、JDK、Android、eclipse、appium 等环境安装 2、启动appium server端 3、run,举例说明~~ /** * example用例 */ @Test public void test_000_example() { Gotocate(1); Sleep(2000); //文案 driver.findElementByAndroidUIAutomator("new UiSelector().text(\"餐饮\")").click(); Sleep(2000); driver.findElementById("com.baidu.lbs.waimai:id/back").click(); Sleep(2000); //id driver.findElementById("com.baidu.lbs.waimai:id/left_container").click(); Sleep(2000); driver.findElementById("com.baidu.lbs.waimai:id/actionbar_left").click(); Sleep(1000); //xpath driver.findElementByXPath("//android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]").click(); Sleep(2000); driver.findElementById("com.baidu.lbs.waimai:id/back").click(); Sleep(2000); //类名--推荐在View数量小的页面使用 //滑动--下拉 int width = driver.manage().window().getSize().width; int height = driver.manage().window().getSize().height; for(int i = 0; i < 10; i++) { driver.swipe(width / 2, height * 3 / 4, width / 2, height / 4, 1000); } // WaitForStringShow("餐饮"); // WaitForViewShow("com.baidu.lbs.waimai:id/left_container"); // WaitForViewHide("com.baidu.lbs.waimai:id/left_container"); } 五、失败case问题定位 三种可能:1、bug—>提icafe;2、脚本问题->Fix;3、工具问题->寻求其他方式解决;4、环境准备问题(无网、手机无电、有弹窗、目标app后台未杀死等等) 定位问题方式: 1、查看失败case截图 2、定位代码行,查看出错原因(函数级) 3、结合功能,确定出错点 特例:crash,无结果收集,需手工复现

优秀的个人博客,低调大师

iOS_UI进阶【拖拽排序】的实现

导读 拖拽排序是新闻类的App可以说是必有的交互设计,如今日头条,网易新闻等。拖拽排序是一个交互体验非常好的设计,简单,方便。 github地址:https://github.com/HelloYeah/DraggingSort 欢迎Star,予人玫瑰,手有余香。 今日头条的拖拽排序界面 我实现的长按拖拽排序效果 实现方案 1.给CollectionViewCell添加一个长按手势,通过协议把手势传递到collectionView所在的控制器中。 - (void)awakeFromNib{ self.layer.cornerRadius = 3; self.layer.masksToBounds = YES; //给每个cell添加一个长按手势 UILongPressGestureRecognizer * longPress =[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)]; longPress.delegate = self; [self addGestureRecognizer:longPress]; } - (void)longPress:(UILongPressGestureRecognizer *)longPress{ if (self.delegate && [self.delegate respondsToSelector:@selector(longPress:)]) { [self.delegate longPress:longPress]; } } 2.开始长按时对cell进行截图,并隐藏cell。 - (void)longPress:(UILongPressGestureRecognizer *)longPress{ //记录上一次手势的位置 static CGPoint startPoint; //触发长按手势的cell MovingCell * cell = (MovingCell *)longPress.view; //开始长按 if (longPress.state == UIGestureRecognizerStateBegan) { [self shakeAllCell]; //获取cell的截图 _snapshotView = [cell snapshotViewAfterScreenUpdates:YES]; _snapshotView.center = cell.center; [_collectionView addSubview:_snapshotView]; _indexPath= [_collectionView indexPathForCell:cell]; _originalCell = cell; _originalCell.hidden = YES; startPoint = [longPress locationInView:_collectionView]; } 3、在手势移动的时候,移动截图视图,用遍历的方法求出截图移动到哪个cell的位置,再调用系统的api交换这个cell和隐藏cell的位置,并且数据源中的数据也需要调整顺序 //手势移动的时候 else if (longPress.state == UIGestureRecognizerStateChanged){ CGFloat tranX = [longPress locationOfTouch:0 inView:_collectionView].x - startPoint.x; CGFloat tranY = [longPress locationOfTouch:0 inView:_collectionView].y - startPoint.y; //设置截图视图位置 _snapshotView.center = CGPointApplyAffineTransform(_snapshotView.center, CGAffineTransformMakeTranslation(tranX, tranY)); startPoint = [longPress locationOfTouch:0 inView:_collectionView]; //计算截图视图和哪个cell相交 for (UICollectionViewCell *cell in [_collectionView visibleCells]) { //跳过隐藏的cell if ([_collectionView indexPathForCell:cell] == _indexPath) { continue; } //计算中心距 CGFloat space = sqrtf(pow(_snapshotView.center.x - cell.center.x, 2) + powf(_snapshotView.center.y - cell.center.y, 2)); //如果相交一半且两个视图Y的绝对值小于高度的一半就移动 if (space <= _snapshotView.bounds.size.width * 0.5 && (fabs(_snapshotView.center.y - cell.center.y) <= _snapshotView.bounds.size.height * 0.5)) { _nextIndexPath = [_collectionView indexPathForCell:cell]; if (_nextIndexPath.item > _indexPath.item) { for (NSUInteger i = _indexPath.item; i < _nextIndexPath.item ; i ++) { [self.array exchangeObjectAtIndex:i withObjectAtIndex:i + 1]; } }else{ for (NSUInteger i = _indexPath.item; i > _nextIndexPath.item ; i --) { [self.array exchangeObjectAtIndex:i withObjectAtIndex:i - 1]; } } //移动 [_collectionView moveItemAtIndexPath:_indexPath toIndexPath:_nextIndexPath]; //设置移动后的起始indexPath _indexPath = _nextIndexPath; break; } } 4.手势停止时,移除截图的view,显示隐藏cell //手势停止时 }else if(longPress.state == UIGestureRecognizerStateEnded){ [self stopShake]; [_snapshotView removeFromSuperview]; _originalCell.hidden = NO; } 其他 代码还可以进一步封装,写一个数据管理类dataTool,dataTool作为collectionView的数据源,所有的数据源方法都写到dataTool类中。手势的代理方法也在里面实现,这样控制器会简洁很多,控制器就不需要关注拖拽排序的具体逻辑了。大家有空可以自己写写看,也许你们有更好的处理方案,可以评论交流一下。 github地址:https://github.com/HelloYeah/DraggingSort 提示 如果你们是从iOS9开始适配的话,那么可以用系统的Api,非常简单好用 //是否允许拖拽 - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(9_0); /** * 从sourceIndexPath 拖拽至destinationIndexPath,在这个代理方法里修改数据源即可。 * exchangeObjectAtIndex:sourceIndexPath.item withObjectAtIndex: destinationIndexPath.item */ - (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath NS_AVAILABLE_IOS(9_0);

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码