我为 Android应用的自动化测试编写了 python测试套件。这套诉讼中有多个测试案例。我现在只放了2个。
问题在于,在每个测试用例之后,应用程序都会被卸载,然后重新安装。每个测试用例都会发生这种情况 卸载并重新安装需要花费很多时间..
我使用的Appium版本是 1.5.0
我尝试过使用:
desired_caps ['noReset'] ='true'
desired_caps ['fullReset'] ='false'
和
appium --no-reset
但是,没有用......
这是我的python代码文件 playpause.py :
class MaverickAndroidTests(unittest.TestCase):
def setUp(self):
"Setup for the test"
desired_caps = {}
desired_caps['browserName']=''
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = 'karthikphone1'
desired_caps['app'] = '/home/karthik/appiumworkspace/tests/app-debug (8).apk'
desired_caps['noReset'] = 'true'
desired_caps['fullReset'] = 'false'
desired_caps['appPackage'] = 'com.prueba.maverick'
desired_caps['app-activity'] = '.SplashActivity'
desired_caps['app-wait-activity'] = '.CommonViewActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def test_on_play_and_pause(self):
self.driver.implicitly_wait(15) # seconds
print(" ")
element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.ID, "tabs")))
self.assertIsNotNone(element)
element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.XPATH, "//android.widget.TextView[@text='RECORD']")))
self.assertIsNotNone(element)
print element.text
element.click() #click on RECORD tab
element = WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
self.assertEqual("PRESS TO RECORD", element.text, "not equal")
print(element.text)
element.click()
time.sleep(4)
element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
self.assertEqual("RECORDING... PRESS TO STOP", element.text, "not equal")
print(element.text)
element.click()
time.sleep(1)
element = WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.ID, "Btn_Save")))
element.click()
time.sleep(2)
print(' ')
print('AUDIO RECORDED SUCCESSFULLY')
print(" ")
def test_indefinite_times_Pausing_and_Unpausing(self):
element = WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
self.assertEqual("PRESS TO RECORD", element.text, "not equal")
print(element.text)
element.click()
time.sleep(4)
element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
self.assertEqual("RECORDING... PRESS TO STOP", element.text, "not equal")
print(element.text)
element.click()
time.sleep(1)
element = WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
self.assertEqual("PAUSED... PRESS TO RESUME", element.text, "not equal")
print(element.text)
element.click()
time.sleep(4)
def tearDown(self):
"Tear down the test"
# self.driver.quit()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(MaverickAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)
我已经评论了拆解功能中的退出声明..
Python终端错误消息:
karthik@dkarnik2-Vostro-3558:~/appiumworkspace/appium-1.4.13/submodules/sample-code/examples/python$ python playpause.py
test_on_play_and_pause (__main__.MaverickAndroidTests) ...
RECORD
PRESS TO RECORD
RECORDING... PRESS TO STOP
AUDIO RECORDED SUCCESSFULLY
ok
test_save_recording_without_pausing (__main__.MaverickAndroidTests) ... ERROR
======================================================================
ERROR: test_save_recording_without_pausing (__main__.MaverickAndroidTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "playpause.py", line 27, in setUp
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
File "/usr/local/lib/python2.7/dist-packages/appium/webdriver/webdriver.py", line 36, in __init__
super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 87, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 141, in start_session
'desiredCapabilities': desired_capabilities,
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: A new session could not be created. Details: Problem getting session data for driver type AndroidDriver; does it implement 'get driverData'?
----------------------------------------------------------------------
Ran 2 tests in 29.605s
FAILED (errors=1)
karthik@dkarnik2-Vostro-3558:~/appiumworkspace/appium-1.4.13/submodules/sample-code/examples/python$
Appium终端错误消息
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getText
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"RECORDING... PRESS TO STOP","status":0}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.getText() result: "RECORDING... PRESS TO STOP"
[HTTP] <-- GET /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/text 200 59 ms - 100
[HTTP] --> GET /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/text
[MJSONWP] Calling AppiumDriver.getText() with args: ["4","2360f77e-917e-401d-bb65-fc8ab03a8da3"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:getText","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getText
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"RECORDING... PRESS TO STOP","status":0}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.getText() result: "RECORDING... PRESS TO STOP"
[HTTP] <-- GET /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/text 200 42 ms - 100
[HTTP] --> POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/click
[MJSONWP] Calling AppiumDriver.click() with args: ["4","2360f77e-917e-401d-bb65-fc8ab03a8da3"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[debug] [AndroidBootstrap] Received command result from bootstrap
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":true,"status":0}
[MJSONWP] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/click 200 696 ms - 76
[HTTP] --> POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element
[MJSONWP] Calling AppiumDriver.findElement() with args: ["id","Btn_Save","2360f77e-917e-401d-bb65-fc8ab03a8da3"]
[debug] [BaseDriver] Waiting up to 15000 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"Btn_Save","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"Btn_Save","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding Btn_Save using ID with the contextId: multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.prueba.maverick:id/Btn_Save]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":{"ELEMENT":"5"},"status":0}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"5"}
[HTTP] <-- POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element 200 27 ms - 87
[HTTP] --> POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/5/click
[MJSONWP] Calling AppiumDriver.click() with args: ["5","2360f77e-917e-401d-bb65-fc8ab03a8da3"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"5"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"5"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":true,"status":0}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/5/click 200 189 ms - 76
[HTTP] --> POST /wd/hub/session
[MJSONWP] Calling AppiumDriver.createSession() with args: [{"deviceName":"karthikphone1","app":"/home/karthik/appiumworkspace/tests/app-debug (8).apk","noReset":"true","app-wait-activity":".CommonViewActiv...
[Appium] Creating new AndroidDriver session
[Appium] Capabilities:
[Appium] deviceName: 'karthikphone1'
[Appium] app: '/home/karthik/appiumworkspace/tests/app-debug (8).apk'
[Appium] noReset: 'true'
[Appium] app-wait-activity: '.CommonViewActivity'
[Appium] browserName: ''
[Appium] fullReset: 'false'
[Appium] platformVersion: '4.4.2'
[Appium] appPackage: 'com.prueba.maverick'
[Appium] platformName: 'Android'
[Appium] app-activity: '.SplashActivity'
[HTTP] <-- POST /wd/hub/session 500 15 ms - 193
请帮帮我..
答案 0 :(得分:2)
在appium 1.5版上他们更改了命令行参数,你现在应该这样使用它:
appium --default-capabilities '{"noReset":true}'
有关appium网站的更多信息: http://appium.io/slate/en/1.5/?ruby#the---default-capabilities-flag
答案 1 :(得分:1)
在每个测试用例之前对此进行评论,
> def tearDown(self):
> "Tear down the test"
> self.driver.quit()
并仅在最后一个测试用例结束时运行它。因为这会杀死appium会话