How to use stop_testserver method in robotframework-androidlibrary

Best Python code snippet using robotframework-androidlibrary_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...289 for node in xmldoc.getElementsByTagName("action"):290 if node.getAttribute("android:name") == "android.intent.action.MAIN":291 return package, node.parentNode.parentNode.getAttribute("android:name")292 return package, None293 def stop_testserver(self):294 '''295 Halts a previously started Android Emulator.296 '''297 assert self._testserver_proc is not None, 'Tried to stop a previously started test server, but it was not started.'298 response = self._request("get", urljoin(self._url, 'kill'))299 assert response.status_code == 200, "InstrumentationBackend sent status %d, expected 200" % response.status_code300 assert response.text == 'Affirmative!', "InstrumentationBackend replied '%s', expected 'Affirmative'" % response.text301 def connect_to_testserver(self):302 '''303 Connect to the previously started test server inside the Android304 Application. Performs a handshake.305 '''306 response = self._request("get", urljoin(self._url, 'ping'))307 assert response.status_code == 200, "InstrumentationBackend sent status %d, expected 200" % response.status_code...

Full Screen

Full Screen

testserver_selftest.py

Source:testserver_selftest.py Github

copy

Full Screen

...43 self.sturdyness_test()44 self.selftest()45 finally:46 print ansi_green('> STOPPING TESTSERVER')47 self.stop_testserver()48 def selftest(self):49 with browser:50 self.testserverctl('zodb_setup')51 with browser.expect_unauthorized():52 browser.open(self.plone_url)53 browser.fill({'Benutzername': SITE_OWNER_NAME,54 'Passwort': SITE_OWNER_PASSWORD}).submit()55 browser.replace_request_header('Accept', 'application/json')56 browser.replace_request_header('Content-Type', 'application/json')57 search_url = (58 self.plone_url59 + '@solrsearch?fq=path_parent:\\/ordnungssystem\\/rechnungspruefungskommission&fl=path,UID'60 )61 browser.open(search_url)62 self.assertEqual(63 {u'/plone/ordnungssystem/rechnungspruefungskommission': u'createrepositorytree000000000004'},64 {item['path']: item['UID'] for item in browser.json['items']})65 data = {'@type': 'opengever.dossier.businesscasedossier',66 'title': u'Gesch\xe4ftsdossier',67 'responsible': 'kathi.barfuss'}68 browser.open(self.plone_url + 'ordnungssystem/rechnungspruefungskommission',69 method='POST',70 data=json.dumps(data))71 dossier_url = browser.json['@id']72 browser.open(dossier_url)73 self.assertDictContainsSubset(74 {u'title': u'Gesch\xe4ftsdossier',75 u'modified': u'2018-11-22T14:29:33+00:00',76 u'UID': u'testserversession000000000000001',77 u'email': u'99001@example.org'},78 browser.json)79 # Make sure the dossier is not yet in the ist of favorites80 favorites_url = self.plone_url + '/@favorites/' + SITE_OWNER_NAME81 dossier_oguid = browser.json['oguid']82 browser.open(favorites_url)83 self.assertNotIn(dossier_oguid, [favorite['oguid'] for favorite in browser.json],84 'The fixture has changed and the dossier is now a favorite by default. '85 'The test needs to be changed.')86 # Add the dossier to the list of favorites and verify that it is there.87 browser.open(favorites_url, method='POST', data=json.dumps({'oguid': dossier_oguid}))88 browser.open(favorites_url)89 self.assertIn(dossier_oguid, [favorite['oguid'] for favorite in browser.json],90 'Marking the dossier seems to not have worked - the test case does not work.')91 browser.open(search_url)92 self.assertEqual(93 {u'/plone/ordnungssystem/rechnungspruefungskommission': u'createrepositorytree000000000004',94 u'/plone/ordnungssystem/rechnungspruefungskommission/dossier-21': u'testserversession000000000000001'},95 {item['path']: item['UID'] for item in browser.json['items']})96 self.testserverctl('zodb_teardown')97 self.testserverctl('zodb_setup')98 with browser.expect_http_error(404):99 browser.open(dossier_url)100 browser.open(search_url)101 self.assertEqual(102 {u'/plone/ordnungssystem/rechnungspruefungskommission': u'createrepositorytree000000000004'},103 {item['path']: item['UID'] for item in browser.json['items']})104 # Make sure the bumblebee checksum is available:105 browser.open(self.plone_url + '@solrsearch?fq=id:document-1&fl=id,bumblebee_checksum')106 self.assertEqual(107 [{'bumblebee_checksum': '9fb7bce1d9bc0eb51d26ea7018ad41f542851ed75cb21e33e04b65a7f9757028',108 'id': 'document-1',109 'UID': u'createtemplates00000000000000002'}],110 browser.json['items'])111 # Make sure that the SQL isolation works by checking whether the favorite we added112 # before teardown/setup is properly removed.113 browser.open(favorites_url)114 self.assertNotIn(dossier_oguid, [favorite['oguid'] for favorite in browser.json],115 'SQL isolation does not work properly.')116 self.testserverctl('zodb_teardown')117 def sturdyness_test(self):118 """This test makes sure that the testserver is sturdy enough, meaning that we can119 make requests while doing isolation without breaking it.120 """121 controller_proxy = xmlrpclib.ServerProxy(self.xmlrpc_url)122 def isolate():123 controller_proxy.isolate()124 isolation_thread = threading.Thread(target=isolate)125 # What we are doing here is basically trigger isolaten and then make126 # an @config request before isolation has finished. This usually127 # causes a "KeyError: 'test-stack-4'" and then breaks the DB connection.128 # It usually breaks on each attempt, altough this depends on the machine load.129 with browser:130 browser.replace_request_header('Accept', 'application/json')131 browser.replace_request_header('Content-Type', 'application/json')132 isolation_thread.start()133 browser.open(self.plone_url + '@config')134 isolation_thread.join()135 controller_proxy.zodb_teardown()136 def testserverctl(self, *args):137 args = ['bin/testserverctl'] + list(args)138 print ansi_blue('>', *args)139 subprocess.check_call(args)140 def start_testserver(self):141 """Start the testserver in a subprocess controlled by a separate thread.142 """143 args = ['bin/testserver', '-v']144 print ansi_blue('>', *args)145 self.testserver_process = subprocess.Popen(args, stdout=subprocess.PIPE)146 def run_and_observe_process():147 while True:148 rc = self.testserver_process.poll()149 if rc is not None:150 return rc151 line = self.testserver_process.stdout.readline()152 sys.stdout.write(line)153 if not self.plone_url and line.startswith('ZSERVER: '):154 self.plone_url = '{}/plone/'.format(line[len('ZSERVER: '):].strip())155 if not self.xmlrpc_url and line.startswith('XMLRPC: '):156 self.xmlrpc_url = line[len('XMLRPC: '):].strip()157 os.environ['TESTSERVER_CTL_PORT'] = str(urlparse(self.xmlrpc_url).port)158 self.testserver_thread = Thread(target=run_and_observe_process)159 self.testserver_thread.start()160 def wait_for_testserver(self):161 """Block until the testserver is ready.162 """163 timeout_seconds = 60 * 5164 interval = 0.1165 steps = timeout_seconds / interval166 # Wait for urls to be appear. The urls are set from the thread watching167 # the bin/testserver subprocess.168 for num in range(int(steps)):169 if self.xmlrpc_url and self.plone_url:170 break171 if num > 300 and num % 300 == 0:172 print ansi_gray('... waiting for testserver to be ready ')173 sleep(interval)174 # A soon as the URLs appear we can setup the XMLRPC proxy.175 self.controller_proxy = xmlrpclib.ServerProxy(self.xmlrpc_url)176 # Now wait until the server is actually ready.177 for num in range(int(steps)):178 if self.is_controller_server_ready():179 return180 if num > 300 and num % 300 == 0:181 print ansi_gray('... waiting for testserver to be ready ')182 sleep(interval)183 self.stop_testserver()184 raise Exception('Timeout: testserver did not start in {} seconds'.format(timeout_seconds))185 def stop_testserver(self):186 """Kill the testserver process group.187 It should be killed as group since bin/testserver is a wrapper script,188 creating a subprocess.189 """190 try:191 os.kill(self.testserver_process.pid, signal.SIGINT)192 except KeyboardInterrupt:193 pass194 except OSError as exc:195 if exc.strerror != 'No such process':196 raise197 self.testserver_thread.join()198 def is_controller_server_ready(self):199 """Test whether the controller server is available....

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-androidlibrary 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