How to use switch_to_webview method in Robotframework-anywherelibrary

Best Python code snippet using robotframework-anywherelibrary

test2.py

Source:test2.py Github

copy

Full Screen

...15server_url = {16 'hostname': 'localhost',17 'port': 345618}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__':...

Full Screen

Full Screen

macaca-ios-sample.test.py

Source:macaca-ios-sample.test.py Github

copy

Full Screen

...12server_url = {13 'hostname': 'localhost',14 'port': 345615}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__':...

Full Screen

Full Screen

macaca_chrome.py

Source:macaca_chrome.py Github

copy

Full Screen

...26 def test_datebao(self):27 self.driver.get("https://m.datebao.com")28 """Login"""29 #WEBVIEW30 switch_to_webview(self.driver).wait_for_element("id","icenterFooter").click()31 switch_to_webview(self.driver).wait_for_element("link text","登录").click()32 switch_to_webview(self.driver).wait_for_element("xpath","//li[@tab='prReg']").click()33 self.driver.wait_for_element("class name",'name').send_keys("18910505634")34 self.driver.wait_for_element("name",'password').send_keys("jinlong1990")35 time.sleep(1)36 self.driver.wait_for_element('class name','loginBtn').click()37 """insurance"""38 time.sleep(3)39 switch_to_webview(self.driver).wait_for_element('id','ilistFooter').click() #点击保险40 switch_to_webview(self.driver).wait_for_element('xpath',"//li[@data-tab='jiankang']").click()41 self.driver.context = self.driver.contexts[0]42 print u'滑动前:self.driver.context',self.driver.context43 time.sleep(3)44 BasePage(self.driver).swipe_up(steps=0.05)45 time.sleep(1)46 BasePage(self.driver).swipe_up(steps=0.05)47 switch_to_webview(self.driver).wait_for_element('xpath',"//div[@class='tab tab1']//a[@href='https://m.datebao.com/product/show/543']").click()48 switch_to_webview(self.driver).wait_for_element("xpath","//li[@data-id=545]").click()49 self.driver.wait_for_element("xpath","//li[@data-value='无社保']").click()50 def tearDown(self):51 self.driver.quit()52if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Robotframework-anywherelibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful