Reputation: 297
I am new to appium python client and need your suggestions to solve my below issue.PFA uiautomator viewer
screen shot.Not sure if this is the reason: after typing into email field, a keyboard opens up so password and sign in button are not located
I have downloaded a free sample xxx.apk and created below script to test it:
class CareZoneAndroidTests(unittest.TestCase):
"Class to run tests against the Care Zone 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/CareZone_v6.6.0.0 (flagship)_apkpure.com.apk'))
desired_caps['appPackage'] = 'com.carezone.caredroid.careapp.medications'
desired_caps['appActivity'] = 'com.carezone.caredroid.careapp.ui.activity.LandingActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def tearDown(self):
"Tear down the test"
self.driver.quit()
def test_login(self):
"Test the Login Page launches correctly"
self.driver.implicitly_wait(120)
print "After WAIT----------------->>>>>>>"
#Click on Sign in button
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_toolbar_action")
self.driver.implicitly_wait(15)
element.click()
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_mail_edit")
self.driver.implicitly_wait(10)
element.click()
element.send_keys("[email protected]");
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_password_edit")
element.click()
element.send_keys("abc");
self.driver.implicitly_wait(10)
#element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_bton")
#element = self.driver.find_element_by_accessibility_id('Sign In')
element = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Sign In")')
element.click()
Issue:
test_login (main.CareZoneAndroidTests) Test the Login Page launches correctly ... After WAIT----------------->>>>>>> ERROR
====================================================================== ERROR: test_login (main.CareZoneAndroidTests) Test the Login Page launches correctly ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\Programs\myapp\CareZoneTests.py", line 42, in test_login element = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Sign In")') File "D:\Programs\Python275\lib\site-packages\appium\webdriver\webdriver.py", line 133, in find_element_by_android_uiautomator return self.find_element(by=By.ANDROID_UIAUTOMATOR, value=uia_string) File "D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element 'value': value})['value'] File "D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute self.error_handler.check_response(response) File "D:\Programs\Python275\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response raise wde NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
Tried below but all are failing for the same reason:
element = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Sign In")')
Upvotes: 1
Views: 1796
Reputation: 297
Below code worked fine for me:
class CareZoneAndroidTests(unittest.TestCase):
"Class to run tests against the Care Zone 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/CareZone_v6.6.0.0 (flagship)_apkpure.com.apk'))
desired_caps['appPackage'] = 'com.carezone.caredroid.careapp.medications'
desired_caps['appActivity'] = 'com.carezone.caredroid.careapp.ui.activity.LandingActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def tearDown(self):
"Tear down the test"
self.driver.quit()
def test_login(self):
"Test the Login Page launches correctly"
self.driver.implicitly_wait(120)
print "Sign in Page"
element = self.driver.find_element_by_xpath("//android.widget.TextView[@text='Have an account? Sign In']")
self.driver.implicitly_wait(15)
element.click()
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_mail_edit")
element.click()
element.send_keys("[email protected]");
self.driver.implicitly_wait(3)
self.driver.keyevent(61)
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_password_edit")
element.click()
element.send_keys("ni");
self.driver.implicitly_wait(3)
print "Click TABS 2 times to get Sign In button-->>>>>>>"
self.driver.keyevent(61)
self.driver.keyevent(61)
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_bton")
element.click()
self.driver.implicitly_wait(120)
print "TEST OK"
Upvotes: 0
Reputation: 2460
Try to find element by ID :
updated :
Try to put hidekeyboard();
before doing the action of selection an element in order to hide your keyboard !
Upvotes: 1