0

I start appium server and launch emulator from avd manager manually. Both these steps I want to automate using appium python client. Would you please give some pointers regarding the same:

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)
falsetru
  • 357,413
  • 63
  • 732
  • 636
JLyon
  • 297
  • 1
  • 4
  • 19

1 Answers1

1

I wanted to do the exact same thing. I did it like this:

    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)

Note that there will be a delay between launching the emulator and starting the script, it may be wise to do these separately. You can also define Appium capabilities if you want by adding them to the command.

You may also need to define your appium path, behind 'appium' in the command. Sometimes Popen requires the full path or it throws 172 error. I hope this helped.

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

Josh Bloom
  • 167
  • 1
  • 2
  • 11