0

I'm new to python with android. I need to write python script. basically what I want to do is when you click first view, I need to load second view. second view has button, when it press that I need to load third view.

class SimpleAndroidTests(unittest.TestCase):
def setUp(self):
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '4.2'
    desired_caps['deviceName'] = 'Android Emulator'
    desired_caps['app'] = PATH(
        'mypath/aaa.apk'
    )
    desired_caps['appPackage'] = 'com.xxxx'

    self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

def test_find_elementsFirstview(self):
    time.sleep(13)
    textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
    textfields[0].send_keys("first text")
    textfields[1].send_keys("second text")

    el = self.driver.find_element_by_name("press Login")
    el.click()

def test_secondView(self):
  time.sleep(10)
  textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
  textfields[2].send_keys("secondviewinput2")

def tearDown(self):
     # end the session
     self.driver.quit()

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

ISSUE is it is not entering to the second view. It is re-loding first view again. please help...

2 Answers 2

2

In your code you have a method - setUp(self) - which nose tools interprets as a "test setup" method, meaning it will be run before each test. Since your setUp() method instantiates the webdriver it is reloading your app before each test. Consider moving your driver instantiation to a setUpClass(), which nose tools will run before all tests in the file.

Example test file:

class YourTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        [...runs before all tests...]

    def setUp(self):
        [...runs before each test...]

    def test_test1(self):
        [...your tests...]

    def tearDown(self):
        [...runs after each test...]

    @classmethod
    def tearDownClass(cls):
        [...runs after all tests...]
Sign up to request clarification or add additional context in comments.

Comments

0

When an element on an android app is clicked via appium python script, then appium has no control over the expected behavior. It is the app that handles the click. So for example, if there is a Login button and if you do this:

el = self.driver.find_element_by_name("press Login")
el.click()

This click on the element is handled by the app and app will take over the flow from here. It is app that launches the next screen. For example, it could be a form.

Basically, appium python client has control over which UI element to choose, but what that particular UI element will do is up to the app.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.