2017-03-05 48 views
0

我手動啓動appium服務器並從avd管理器啓動模擬器。 這兩個步驟我想使用appium python客戶端自動化。 請您給一些指點關於相同:從appium python客戶端啓動模擬器

class ChessAndroidTests(unittest.TestCase): 
    "Class to run tests against the Chess Free app" 
    def setUp(self): 
     "Setup for the test" 
     desired_caps = {} 
     desired_caps['platformName'] = 'Android' 
     desired_caps['platformVersion'] = '4.2' 
     desired_caps['deviceName'] = 'Android Emulator' 
     # Returns abs path relative to this file and not cwd 
     desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'D:\Programs\myapp\Chess Free.apk')) 
     desired_caps['appPackage'] = 'uk.co.aifactory.chessfree' 
     desired_caps['appActivity'] = '.ChessFreeActivity' 
     self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) 

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

    def test_single_player_mode(self): 
     "Test the Single Player mode launches correctly" 
     element = self.driver.find_element_by_name("PLAY!") 
     element.click() 
     self.driver.find_element_by_name("Single Player").click() 
     textfields = self.driver.find_elements_by_class_name("android.widget.TextView") 
     self.assertEqual('MATCH SETTINGS', textfields[0].text) 

#---START OF SCRIPT 
if __name__ == '__main__': 
    suite = unittest.TestLoader().loadTestsFromTestCase(ChessAndroidTests) 
    unittest.TextTestRunner(verbosity=2).run(suite) 

回答

0

我想做同樣的事情。 我做了這樣的:

def runAll(self,*args): 
    subprocess.Popen(['/Users/User/Library/Android/sdk/tools/emulator -netdelay none -netspeed full -avd Nexus_5X_API_22'],shell=True) 
    subprocess.Popen(['appium --avd Nexus_5X_API_22'],shell=True) 
    subprocess.Popen(['mocha /Users/User/Documents/dev/engineerappcopy/tests/testLoginPage.js --platform android'],shell=True) 

注意,會有啓動仿真器和啓動腳本之間的延遲,它可能是明智的,單獨做這些。您也可以通過將Appium功能添加到命令中來定義Appium功能。

您可能還需要在命令後面的'appium'後面定義您的appium路徑。有時Popen需要完整路徑,否則會引發172錯誤。 我希望這有助於。

https://docs.python.org/2/library/subprocess.html