Best Python code snippet using robotframework-appiumlibrary_python
test_multipleAppiumConnections.py
Source:test_multipleAppiumConnections.py
...36 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice02')37 self.assertEqual(appIndex, 2)38 self.am.lock()39 # switch to 1st application - alias=MyAppA - index=2 (switch_application returns the previous app index)40 appIndex = self.am.switch_application('MyAppA')41 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4723')42 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice01')43 self.assertEqual(appIndex, 2)44 self.am.lock()45 # create 3rd application - alias=MyAppC - index=346 appIndex = self.am.open_application('http://127.0.0.1:4743/wd/hub', alias='MyAppC', platformName='Android', platformVersion='4.4', deviceName='MyDevice03')47 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4743')48 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice03')49 self.assertEqual(appIndex, 3)50 self.am.lock()51 # switch to 2nd application - alias=MyAppB - index=3 (switch_application returns the previous app index)52 appIndex = self.am.switch_application('MyAppB')53 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4733')54 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice02')55 self.assertEqual(appIndex, 3)56 self.am.lock()57 def test_MAC_openApplicationDuplAlias_successful(self):58 self.assertFalse(self.am._cache.current)59 ## open with duplicate alias - should Fail60 # bug/Feature in ConnectionCache? It's possible to add duplicate alias61 # --> old alias is overwritten with the new, however old connection remains open and 62 # is still accessible with the connection index 63 # see https://github.com/robotframework/SSHLibrary/issues/121 64 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')65 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02')66 ## open + close + open again with the same alias (different url etc.) - should succeed67 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')68 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02') 69 self.am.close_application()70 self.am.open_application('http://127.0.0.1:4743/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice03') 71 def test_MAC_switchWithAlias_successful(self):72 # switch applications with aliases73 self.assertFalse(self.am._cache.current)74 # create 1st application - alias=MyAppA - index=175 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')76 # create 2nd application - alias=MyAppB - index=277 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02') 78 # switch to 1st application - alias=MyAppA - index=2 (switch_application returns the previous app index)79 appIndex = self.am.switch_application('MyAppA')80 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4723')81 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice01')82 self.assertEqual(appIndex, 2)83 self.am.lock()84 # create 3rd application - alias=MyAppC - index=385 self.am.open_application('http://127.0.0.1:4743/wd/hub', alias='MyAppC', platformName='Android', platformVersion='4.4', deviceName='MyDevice03') 86 # switch to 2nd application - alias=MyAppB - index=3 (switch_application returns the previous app index)87 appIndex = self.am.switch_application('MyAppB')88 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4733')89 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice02')90 self.assertEqual(appIndex, 3)91 self.am.lock()92 # switch back to 3nd application - alias=MyAppC - index=2 (switch_application returns the previous app index)93 appIndex = self.am.switch_application('MyAppC')94 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4743')95 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice03')96 self.assertEqual(appIndex, 2)97 self.am.lock()98 def test_MAC_switchWithAlias_failed(self):99 ## switch applications with non-existent aliases100 # switch - no connections open101 self.assertRaisesRegexp(RuntimeError, "Non-existing.*MyAppA", self.am.switch_application, 'MyAppA')102 # create 1st application - alias=MyAppA - index=1103 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')104 # create 2nd application - alias=MyAppB - index=2105 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02') 106 # switch to non-existent alias107 self.assertRaisesRegexp(RuntimeError, "Non-existing.*MyAppXXX", self.am.switch_application, 'MyAppXXX')108 def test_MAC_switchWithIndex_successful(self):109 # switch applications with indices110 self.assertFalse(self.am._cache.current)111 # create 1st application - alias=MyAppA - index=1112 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')113 # create 2nd application - alias=MyAppB - index=2114 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02') 115 # switch to 1st application - index=1 - appIndex=2 (switch_application returns the previous app index)116 appIndex = self.am.switch_application(1)117 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4723')118 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice01')119 self.assertEqual(appIndex, 2)120 self.am.lock()121 # create 3rd application - alias=MyAppC - index=3122 self.am.open_application('http://127.0.0.1:4743/wd/hub', alias='MyAppC', platformName='Android', platformVersion='4.4', deviceName='MyDevice03') 123 # switch to 2nd application - index=2 - appIndex=3 (switch_application returns the previous app index)124 appIndex = self.am.switch_application(2)125 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4733')126 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice02')127 self.assertEqual(appIndex, 3)128 self.am.lock()129 # switch back to 3nd application - index=3 - appIndex=2 (switch_application returns the previous app index)130 appIndex = self.am.switch_application(appIndex)131 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4743')132 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice03')133 self.assertEqual(appIndex, 2)134 self.am.lock()135 def test_MAC_switchWithIndex_failed(self):136 # switch applications with non-existent index137 # switch - no connections open138 self.assertRaisesRegexp(RuntimeError, "Non-existing.*1", self.am.switch_application, 1)139 # create 1st application - alias=MyAppA - index=1140 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')141 # create 2nd application - alias=MyAppB - index=2142 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02') 143 # switch to non-existent alias144 self.assertRaisesRegexp(RuntimeError, "Non-existing.*333", self.am.switch_application, 333)145 def test_MAC_closeApplication_successful(self):146 # switch applications with aliases147 # create 1st application - alias=MyAppA - index=1148 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')149 # create 2nd application - alias=MyAppB - index=2150 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02') 151 # close and switch to MyAppA152 self.assertTrue(self.am._cache.current)153 self.am.close_application()154 self.assertFalse(self.am._cache.current)155 appIndex = self.am.switch_application(1)156 self.assertTrue(self.am._cache.current)157 self.assertEqual(appIndex, None)158 159 def test_MAC_closeApplication_failed(self):160 # switch applications with aliases161 ## close application without any open applications162 self.assertRaisesRegexp(RuntimeError, "No application is open", self.am.close_application)163 ## execute keywords without any open applications164 self.assertRaisesRegexp(RuntimeError, "No application is open", self.am.lock)165 ## execute keywords after close, without switch166 # create 1st application - alias=MyAppA - index=1167 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')168 # create 2nd application - alias=MyAppB - index=2169 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02') 170 self.am.close_application()171 self.assertRaisesRegexp(RuntimeError, "No application is open", self.am.lock)172 self.am.switch_application(1)173 self.am.lock()174 self.am.close_application()175 # verify that the applications are really closed176 # These fail because of ConnectionCache, it has no mechanism for removing a single entry from the cache177 # --> switching to a closed connection does not produce an error, the error comes only when you try to do 178 # something with the connection179 # BUG: https://github.com/robotframework/SSHLibrary/issues/120180 # Now the WebdriverRemoteMock object, simulates the current situation i.e. it implements 181 # - the "quit()" method that is used to close the application182 # - the "lock()" method (=keyword) to simulate a call to a dead connection183 # When fixed, this test should look something like this: 184 #self.assertRaisesRegexp(RuntimeError, "Non-existing.*2", self.am.switch_application, 2)185 #self.assertRaisesRegexp(RuntimeError, "Non-existing.*MyAppB", self.am.switch_application, 'MyAppA')186 self.am.switch_application(2)187 self.assertRaisesRegexp(RuntimeError, "Application has been closed", self.am.lock)188 189 def test_MAC_switchAndClose_successful(self):190 self.assertFalse(self.am._cache.current)191 # create apps192 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')193 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02')194 self.am.open_application('http://127.0.0.1:4743/wd/hub', alias='MyApp3', platformName='Android', platformVersion='4.4', deviceName='MyDevice03')195 self.am.switch_application(2)196 self.am.close_application()197 self.am.switch_application(3)198 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4743')199 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice03')200 appIndex = self.am.open_application('http://127.0.0.1:4753/wd/hub', alias='MyAppD', platformName='Android', platformVersion='4.4', deviceName='MyDeviDce04')201 self.assertEqual(appIndex, 4)202 appIndex = self.am.switch_application('MyAppA')203 self.assertRegexpMatches(self.am._cache.current._appiumUrl, '127.0.0.1:4723')204 self.assertEqual(self.am._cache.current._desCapa.get('deviceName'), 'MyDevice01')205 206 def test_MAC_closeAll_successful(self):207 # create apps208 self.am.open_application('http://127.0.0.1:4723/wd/hub', alias='MyAppA', platformName='Android', platformVersion='4.4', deviceName='MyDevice01')209 self.am.open_application('http://127.0.0.1:4733/wd/hub', alias='MyAppB', platformName='Android', platformVersion='4.4', deviceName='MyDevice02')210 self.am.open_application('http://127.0.0.1:4743/wd/hub', alias='MyApp3', platformName='Android', platformVersion='4.4', deviceName='MyDevice03')211 self.am.close_all_applications()212 self.assertRaisesRegexp(RuntimeError, "No application is open", self.am.lock)...
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!!