Android应用的功能测试,使用Appium和Python

2024-06-16 15:06:14 发布

您现在位置:Python中文网/ 问答频道 /正文

这是用来检查录制是否正常的python代码:

   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'] = 'd65d04425101de'
       # Returns abs path relative to this file and not cwd
       desired_caps['app'] = '/home/karthik/appiumworkspace/tests/app-debug (2).apk'
       desired_caps['appPackage'] = 'com.prueba.maverick'
       desired_caps['app-activity'] = '.SplashActivity' 
       desired_caps['app-wait-activity'] = '.MainActivity' 
       self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

   def tearDown(self):
       "Tear down the test"
       self.driver.quit()


    def test_whether_app_is_installed(self):
        "Test if the app has been installed correctly"
        self.driver.is_app_installed('com.prueba.maverick')

        print('APP HAS BEEN INSTALLED')


    def test_record_the_audio(self):
       "Test it clicks on Record button correctly"
        element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.NAME, "PRESS TO RECORD")))
        element.click()
        time.sleep(10)
        element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.NAME, "RECORDING PRESS TO STOP")))
        element.click()
        print('AUDIO RECORDED SUCCESSFULLY')        

   if __name__ == '__main__':
       suite = unittest.TestLoader().loadTestsFromTestCase(MaverickAndroidTests)
       unittest.TextTestRunner(verbosity=2).run(suite)

在这里之前都很好。

现在我必须检查物理设备,不管录音是否真实存在。。在

我必须转到设备文件管理器,以检查是否存在录制的音频(录音.mp3)在

我该如何编写测试用例呢??在


Tags: installedthetestselfcomappisdef