Best Python code snippet using robotframework-anywherelibrary
test2.py
Source:test2.py
...19def switch_to_webview(driver):20 contexts = driver.contexts21 driver.context = contexts[-1]22 return driver23def switch_to_native(driver):24 contexts = driver.contexts25 driver.context = contexts[0]26 return driver27class MacacaTest(unittest.TestCase):28 @classmethod29 def setUpClass(cls):30 cls.driver = WebDriver(desired_caps, server_url)31 cls.initDriver()32 @classmethod33 def tearDownClass(cls):34 cls.driver.quit()35 @classmethod36 @retry37 def initDriver(cls):38 print("Retry connecting server...")39 cls.driver.init()40 def test_01_login(self):41 el = self.driver \42 .elements_by_class_name('android.widget.EditText')[0] \43 .send_keys('ä¸æ+Test+12345678') \44 el = self.driver \45 .elements_by_class_name('android.widget.EditText')[1] \46 .send_keys('111111')47 time.sleep(1)48 # self.driver.keys(Keys.ENTER.value + Keys.ESCAPE.value)49 self.driver \50 .element_by_name('Login') \51 .click()52 def test_02_scroll_tableview(self):53 self.driver \54 .wait_for_element_by_name('HOME') \55 .click()56 self.driver \57 .wait_for_element_by_name('list') \58 .click()59 def test_03_gesture(self):60 time.sleep(5)61 self.driver \62 .wait_for_element_by_name('Alert') \63 .click()64 time.sleep(5)65 self.driver \66 .accept_alert()67 time.sleep(3)68 self.driver \69 .back()70 time.sleep(3)71 self.driver \72 .wait_for_element_by_name('Gesture') \73 .click()74 time.sleep(3)75 self.driver \76 .touch('tap', {77 'x': 100,78 'y': 10079 })80 time.sleep(5)81 self.driver \82 .touch('doubleTap', {83 'x': 100,84 'y': 10085 })86 time.sleep(5)87 self.driver \88 .touch('press', {89 'x': 100,90 'y': 100,91 'steps': 10092 })93 time.sleep(5)94 self.driver \95 .touch('drag', {96 'fromX': 100,97 'fromY': 100,98 'toX': 100,99 'toY': 600,100 'steps': 100101 })102 time.sleep(5)103 self.driver.back()104 time.sleep(5)105 self.driver.back()106 def test_04_webview(self):107 self.driver \108 .wait_for_element_by_name('Webview') \109 .click()110 time.sleep(5)111 self.driver.save_screenshot('./webView.png') # save screen shot112 switch_to_webview(self.driver) \113 .wait_for_element_by_id('pushView') \114 .click()115 switch_to_webview(self.driver) \116 .wait_for_element_by_id('popView') \117 .click()118 def test_05_web(self):119 switch_to_native(self.driver) \120 .wait_for_element_by_name('Baidu') \121 .click()122 time.sleep(5)123 self.driver.save_screenshot("./baidu.png")124 switch_to_webview(self.driver) \125 .wait_for_element_by_id('index-kw') \126 .send_keys('macaca')127 self.driver \128 .wait_for_element_by_id('index-bn') \129 .click()130 def test_06_logout(self):131 switch_to_native(self.driver) \132 .wait_for_element_by_name('PERSONAL') \133 .click()134 self.driver.wait_for_element_by_name('Logout') \135 .click()136if __name__ == '__main__':...
macaca-android-sample.test.py
Source:macaca-android-sample.test.py
...16def switch_to_webview(driver):17 contexts = driver.contexts18 driver.context = contexts[-1]19 return driver20def switch_to_native(driver):21 contexts = driver.contexts22 driver.context = contexts[0]23 return driver24class MacacaTest(unittest.TestCase):25 @classmethod26 def setUpClass(cls):27 cls.driver = WebDriver(desired_caps, server_url)28 cls.initDriver()29 @classmethod30 def tearDownClass(cls):31 cls.driver.quit()32 @classmethod33 @retry34 def initDriver(cls):35 print("Retry connecting server...")36 cls.driver.init()37 def test_01_login(self):38 el = self.driver \39 .elements_by_class_name('android.widget.EditText')[0] \40 .send_keys('ä¸æ+Test+12345678') \41 el = self.driver \42 .elements_by_class_name('android.widget.EditText')[1] \43 .send_keys('111111')44 time.sleep(1)45 # self.driver.keys(Keys.ENTER.value + Keys.ESCAPE.value)46 self.driver \47 .element_by_name('Login') \48 .click()49 def test_02_scroll_tableview(self):50 self.driver \51 .wait_for_element_by_name('HOME') \52 .click()53 self.driver \54 .wait_for_element_by_name('list') \55 .click()56 def test_03_gesture(self):57 time.sleep(5)58 self.driver \59 .wait_for_element_by_name('Alert') \60 .click()61 time.sleep(5)62 self.driver \63 .accept_alert()64 time.sleep(3)65 self.driver \66 .back()67 time.sleep(3)68 self.driver \69 .wait_for_element_by_name('Gesture') \70 .click()71 time.sleep(3)72 self.driver \73 .touch('tap', {74 'x': 100,75 'y': 10076 })77 time.sleep(5)78 self.driver \79 .touch('doubleTap', {80 'x': 100,81 'y': 10082 })83 time.sleep(5)84 self.driver \85 .touch('press', {86 'x': 100,87 'y': 100,88 'steps': 10089 })90 time.sleep(5)91 self.driver \92 .touch('drag', {93 'fromX': 100,94 'fromY': 100,95 'toX': 100,96 'toY': 600,97 'steps': 10098 })99 time.sleep(5)100 self.driver.back()101 time.sleep(5)102 self.driver.back()103 def test_04_webview(self):104 self.driver \105 .wait_for_element_by_name('Webview') \106 .click()107 time.sleep(5)108 self.driver.save_screenshot('./webView.png') # save screen shot109 switch_to_webview(self.driver) \110 .wait_for_element_by_id('pushView') \111 .click()112 switch_to_webview(self.driver) \113 .wait_for_element_by_id('popView') \114 .click()115 def test_05_web(self):116 switch_to_native(self.driver) \117 .wait_for_element_by_name('Baidu') \118 .click()119 time.sleep(5)120 self.driver.save_screenshot("./baidu.png")121 switch_to_webview(self.driver) \122 .wait_for_element_by_id('index-kw') \123 .send_keys('macaca')124 self.driver \125 .wait_for_element_by_id('index-bn') \126 .click()127 def test_06_logout(self):128 switch_to_native(self.driver) \129 .wait_for_element_by_name('PERSONAL') \130 .click()131 self.driver.wait_for_element_by_name('Logout') \132 .click()133if __name__ == '__main__':...
macaca-ios-sample.test.py
Source:macaca-ios-sample.test.py
...16def switch_to_webview(driver):17 contexts = driver.contexts18 driver.context = contexts[-1]19 return driver20def switch_to_native(driver):21 contexts = driver.contexts22 driver.context = contexts[0]23 return driver24class MacacaTest(unittest.TestCase):25 @classmethod26 def setUpClass(cls):27 cls.driver = WebDriver(desired_caps, server_url)28 cls.initDriver()29 @classmethod30 def tearDownClass(cls):31 cls.driver.quit()32 @classmethod33 @retry34 def initDriver(cls):35 print("Retry connecting server...")36 cls.driver.init()37 def test_01_login(self):38 self.driver \39 .element_by_xpath('//XCUIElementTypeTextField[1]') \40 .send_keys('ä¸æ+Test+12345678') \41 self.driver \42 .element_by_xpath('//XCUIElementTypeSecureTextField[1]') \43 .send_keys('111111') \44 time.sleep(1)45 self.driver \46 .send_keys('\n')47 self.driver \48 .element_by_name('Login') \49 .click()50 def test_02_scroll_tableview(self):51 self.driver \52 .element_by_name('HOME') \53 .click()54 self.driver \55 .element_by_name('list') \56 .click()57 def test_03_gesture(self):58 self.driver \59 .touch('drag', {60 'fromX': 200,61 'fromY': 400,62 'toX': 200,63 'toY': 100,64 'duration': 265 })66 time.sleep(1)67 self.driver \68 .touch('drag', {69 'fromX': 100,70 'fromY': 100,71 'toX': 100,72 'toY': 400,73 'duration': 274 })75 time.sleep(1)76 self.driver \77 .element_by_name('Gesture') \78 .click()79 self.driver \80 .touch('tap', {81 'x': 100,82 'y': 10083 })84 time.sleep(1)85 self.driver \86 .touch('press', {87 'x': 100,88 'y': 100,89 'duration': 190 })91 time.sleep(1)92 self.driver \93 .element_by_id('info') \94 .touch('pinch', {95 'scale': 2,96 'velocity': 197 })98 time.sleep(1)99 self.driver \100 .touch('drag', {101 'fromX': 100,102 'fromY': 100,103 'toX': 100,104 'toY': 600,105 'steps': 100106 })107 def test_04_webview(self):108 self.driver \109 .element_by_name('Webview') \110 .click()111 time.sleep(3)112 self.driver.save_screenshot('./webView.png') # save screen shot113 switch_to_webview(self.driver) \114 .element_by_id('pushView') \115 .touch('tap')116 switch_to_webview(self.driver) \117 .element_by_id('popView') \118 .touch('tap')119 def test_05_web(self):120 switch_to_native(self.driver) \121 .element_by_name('Baidu') \122 .touch('tap')123 time.sleep(3)124 self.driver.save_screenshot("./baidu.png")125 switch_to_webview(self.driver) \126 .element_by_id('index-kw') \127 .send_keys('macaca') \128 .element_by_id('index-bn') \129 .touch('tap')130 def test_06_logout(self):131 switch_to_native(self.driver) \132 .element_by_name('PERSONAL') \133 .click()134 self.driver.element_by_name('Logout') \135 .click()136if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!