码迷,mamicode.com
首页 > 移动开发 > 详细

Appium 这个问题竟然花了我5分钟进行定位

时间:2018-09-29 14:25:55      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:hub   sel   修改   dev   host   cal   click   rom   写代码   

1、先上问题,知道是什么问题先

 1 EE
 2 ======================================================================
 3 ERROR: testCalcu (__main__.MyTest)
 4 ----------------------------------------------------------------------
 5 Traceback (most recent call last):
 6   File "D:\WorkSpace3\EXAMPLE\Appiu_ex\test.py", line 28, in testCalcu
 7     self.driver.find_element_by_id("com.txt.calculator:id/tv_skip").click()
 8 AttributeError: MyTest object has no attribute driver
 9 
10 ======================================================================
11 ERROR: testCalcu (__main__.MyTest)
12 ----------------------------------------------------------------------
13 Traceback (most recent call last):
14   File "D:\WorkSpace3\EXAMPLE\Appiu_ex\test.py", line 25, in tearDown
15     self.driver.quit()
16 AttributeError: MyTest object has no attribute driver
17 
18 ----------------------------------------------------------------------
19 Ran 1 test in 0.001s
20 
21 FAILED (errors=2)

2、再上源码,如果你也在5分钟内未找到该问题原因,呵呵,那就在后续写代码中一定要仔细再仔细

 1 # -*- coding:utf-8 -*-
 2 from appium import webdriver
 3 import unittest
 4 
 5 class MyTest(unittest.TestCase):
 6     def setup(self):
 7         desired_caps = {}        
 8         desired_caps[platformName] =Android        
 9         desired_caps[platformVersion] =6.0       
10         desired_caps[deviceName] =DIYTHYTCCQBIV47D       
11         desired_caps[appPackage] =com.txt.calculator        
12         desired_caps[appActivity] =.Calculator        
13         desired_caps["unicodeKeyboard"] ="True"        
14         desired_caps["resetKeyboard"] ="True"        
15         self.driver = webdriver.Remote(http://localhost:4723/wd/hub, desired_caps)
16     
17     def tearDown(self):
18         self.driver.quit()
19         
20     def testCalcu(self):
21         self.driver.find_element_by_id("com.txt.calculator:id/tv_skip").click()
22         self.driver.find_element_by_id("com.txt.calculator:id/digit_8").click()
23         self.driver.find_element_by_id("com.txt.calculator:id/op_add").click()
24         self.driver.find_element_by_id("com.txt.calculator:id/digit_5").click()
25         self.driver.find_element_by_id("com.txt.calculator:id/eq").click()
26         try:            
27             result = self.driver.find_element_by_class_name("android.widget.EditText").text
28             self.assertEqual(13, result, "The result isn‘t right")
29         except Exception as e:
30             print (e)
31             self.fail("The element is wrong or non-exists")
32 
33 if __name__ == __main__:
34     unittest.main()

 

3、duang   duang  duang duang开始计时

 

 

 

 

 

 

 

 

 

 

 

 

 

~~~~~5分钟之后,给出出问题的源码

class MyTest(unittest.TestCase):
    def setup(self):

  注意setup   此处 up首字要大写,如未按照unittest框架的要求进行编写,它自然就不会先进行初使化了,自然也就出现后面的报错 MyTest实例中没有driver的属性

修改正确如下:

class MyTest(unittest.TestCase):
    def setUp(self):

  

 

Appium 这个问题竟然花了我5分钟进行定位

标签:hub   sel   修改   dev   host   cal   click   rom   写代码   

原文地址:https://www.cnblogs.com/SaShuangYiBing/p/9723226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!