手把手教你appium_ios第一个例子

4 篇文章 0 订阅
4 篇文章 0 订阅


 

 

参考:

http://www.cnblogs.com/enjoytesting/p/3513637.html

 

参考代码:

https://github.com/appium/appium/blob/master/sample-code/examples/python/simple.py

 

本文示例下载:

包括:自己写的一个很简单的ios例子和上面链接中提到的simple.py,和我修改后的test1.py

http://download.csdn.net/detail/testingba/7200461

 

参考帖子,因为环境已经安装好了,所以第一步就不需要了:

二,Selenium WebDriver

因为是Python版,所以就去Selenium官网下载Python的WebDriver(selenium-2.39.0.tar.gz)

https://pypi.python.org/pypi/selenium

解压:

#gzip -dc selenium-2.39.0.tar.gz | tar xvf -

安装:

#cd selenium-2.39.0

#sudo python setup.py install  //sudo依旧是解决Permission的问题

-----------

这样,WebDriver就安装成功了

 

 

我照着操作了一遍,版本不同了而已,很顺利:

selenium-2.41.0.tar.gz

 

Installed /Library/Python/2.7/site-packages/selenium-2.41.0-py2.7.egg

Processing dependencies for selenium==2.41.0

Finished processing dependencies for selenium==2.41.0

 

 

admins-Mac:selenium-2.41.0 admin$ which python

/usr/bin/python

admins-Mac:selenium-2.41.0 admin$ python -V

Python 2.7.2

 

 

编译例子:

三,要测试的app

测试的是appium提供的TestApp

首先,我们需要用xcode编译这个app

#cd appium

#cd sample-code/apps/TestApp

#xcodebuild -sdk iphonesimulator  //为了防止iphonesimulator和设置的冲突,没有注明iphonesimulator的版本

-----------

如果看到** BUILD SUCCEEDED **,这个TestApp就build成功了。

 

操作的时候,留心先进入到项目目录下:

admins-Mac:testDemo admin$ cd test

admins-Mac:test admin$ ls -l

total 0

drwxr-xr-x  14 admin  staff  476 Apr 22  2013 test

drwxr-xr-x@  5 admin  staff  170 Apr 22  2013 test.xcodeproj

 

admins-Mac:test admin$ xcodebuild -sdk iphonesimulator

Build settings from command line:

SDKROOT = iphonesimulator7.0

=== BUILD TARGET test OF PROJECT test WITH THE DEFAULT CONFIGURATION (Release) ===

 

…..

 

我后来运行的时候老是不能指定某个模拟器加载,而老是加载ios7.0,估计就是这个环节的相关配置引起的,以后有空再研究吧。不过也有群友说文档上说会自动启动最高版本的模拟器,这是不可以修改的。算了,反正以后多半使用真机做。

 

 

看到:** BUILD SUCCEEDED ** 就是编译成功了,在当前目录下就会生成一个build目录,顺带找找app文件在哪里。

admins-Mac:test admin$ pwd

/Users/admin/Documents/demo/testDemo/test

admins-Mac:test admin$ ls -l

total 0

drwxr-xr-x@  4 admin  staff  136 Apr 15 16:02 build

drwxr-xr-x  14 admin  staff  476 Apr 22  2013 test

drwxr-xr-x@  5 admin  staff  170 Apr 22  2013 test.xcodeproj

admins-Mac:test admin$ find build|grep test.app$

build/Release-iphonesimulator/test.app

 

好了,这下可以写测试的python脚本了,我就在这个目录下建立了一个test1.py。因为代码中需要指明app位置,所以留心自己的脚本所在位置和app文件的相对位置。

 

参考的代码就看提供的示例了,我的目的是想试试引用的方法和对应的属性,是title还是label,汉字的是否支持。所以弄了四个控件,两个button,两个testfield

01.png

 

02.png

 

03.png

 

04.png

 

运行:python test1.py

还算顺利,自动加载了模拟器,运行了被测程序,别忘记了启动appium呀。

 

测试:

T1: 脚本中有汉字都不行,哪怕是注释了的,更别说用汉字引用了,据群友说已经有人解决了这个问题,可以去testerhome上搜搜,后续再弄吧。

 

buttons = self.driver.find_elements_by_tag_name("englishname")

buttons[0].click()

 

# button1 = self.driver.find_elements_by_tag_name("汉字计算")

# button1.click()

 

报错:

admins-Mac:test admin$ python test1.py

  File "test1.py", line 40

SyntaxError: Non-ASCII character '\xe6' in file test1.py on line 40, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

 

 

T2:

       button1=self.driver.find_elements_by_tag_name("englishname")

       button1[0].click()

----------------------------------------------------------------------

Traceback (most recent call last):

  File "test1.py", line 38, in test_ui_computation

    button1[0].click()

IndexError: list index out of range

 

T3:

       button1=self.driver.find_elements_by_name("englishname")

       button1[0].click()

----------------------------------------------------------------------

Traceback (most recent call last):

  File "test1.py", line 38, in test_ui_computation

    button1[0].click()

IndexError: list index out of range

 

T4:

       button1=self.driver.find_elements_by_name("buttonacclabel")

       button1[0].click()

OK

 

T5:

删除掉accessiblity label,只留下title属性,重新编译app,运行脚本:

       button1=self.driver.find_elements_by_name("englishname")

       button1[0].click()

----------------------------------------------------------------------

Traceback (most recent call last):

  File "test1.py", line 38, in test_ui_computation

    button1[0].click()

IndexError: list index out of range

 

 

哎哟喂,看来self.driver.find_elements_by_name只能使用控件的accessiblitylabel属性,难道要通知开发把每个控件加上这个属性?

我猜测title可能也有其他的引用方式,只是我没有找到吧?

 

勉强算是弄完了,还有太多的东西不清楚。先写给大家参考参考吧。

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Testingba

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值