Best Python code snippet using uiautomator
yuyinchangshouge.py
Source: yuyinchangshouge.py
1# -*- coding: utf-8 -*-2import urllib23import urllib4import cookielib5import json6import os7import sys8import string9import time10import md511import hashlib12reload(sys)13sys.setdefaultencoding('utf-8')14# first url request15def yuyinchangshouge():16 sn=" -s 1011000000111007 "17 pslogcat="adb "+ sn +"shell \"ps |grep logcat\""18 output = os.popen(pslogcat)19 output = output.read()20 if "root" not in output:21 print "There is not logcat process"22 else:23 str = output.split("root")24 val = str[1]25 val = val.lstrip()26 val = val.split(" ")27 pid = val[0]28 command="adb "+ sn + "shell kill -9 "+ pid29 print command30 os.system(command) 31 rmlog="adb "+ sn +"shell \"rm -fr /sdcard/yuyinchangshouge.log \""32 os.system(rmlog)33 cppcm="adb "+ sn +"shell \"busybox cp /sdcard/nihao.pcm /sdcard/test_wakeup.pcm \""34 os.system(cppcm)35 pidstart = 036 while(pidstart<1):37 pidlogcat="adb "+ sn +"shell \"busybox nohup logcat -v time -f /sdcard/yuyinchangshouge.log & \""38 test=os.popen(pidlogcat)39 time.sleep(3)40 test=test.read()41 if "nohup" in test:42 pidstart = 143 print 'logcat successful'44 else:45 print "logcat failed"46 time.sleep(5)47 48 wakeup = 049 while(wakeup<1):50 amcommand="adb "+ sn +"shell \"am startservice -n com.juan.voiceservice/com.juan.audio.service.TestWakeUpService\""51 os.system(amcommand)52 time.sleep(3)53 checkloghx="adb "+ sn +"shell \"cat /sdcard/yuyinchangshouge.log |grep -E 'å¤é|ä½ å¥½'\""54 output = os.popen(checkloghx)55 res= output.read()56 print "huanxin score:",res57 if 'å¤éè¯' in res or 'ä½ å¥½å¸ä¸' in res:58 wakeup = 159 print 'wakeup successful'60 else:61 print 'wakeup failed'62 63 time.sleep(10) 64 cpclock="adb "+ sn +"shell \"busybox cp /sdcard/changsg.pcm /sdcard/test_wakeup.pcm \""65 os.system(cpclock)66 os.system(amcommand)67 time.sleep(10)68 69 checklogclock="adb "+ sn +"shell \"cat /sdcard/yuyinchangshouge.log |grep paramJasonStr\""70 output = os.popen(checklogclock)71 time.sleep(3)72 res= output.read()73 print "changshouge logcat",res74 if 'singer' in res:75 print 'set changshouge successful';76 else:77 print 'set changshouge failed'78 return False79 80 time.sleep(3)81 82 wakeup = 083 while(wakeup<1):84 cppcm="adb "+ sn +"shell \"busybox cp /sdcard/nihao.pcm /sdcard/test_wakeup.pcm \""85 os.system(cppcm)86 amcommand="adb "+ sn +"shell \"am startservice -n com.juan.voiceservice/com.juan.audio.service.TestWakeUpService\""87 os.system(amcommand)88 time.sleep(3)89 checkloghx="adb "+ sn +"shell \"cat /sdcard/yuyinchangshouge.log |grep score\""90 output = os.popen(checkloghx)91 res= output.read()92 print "daduan score:",res93 if 'wakeup' in res:94 wakeup = 195 print 'daduan successful'96 else:97 print 'daduan failed'98 99 time.sleep(3)100 sleep = 0101 while(sleep<1):102 cpbye="adb "+ sn +"shell \"busybox cp /sdcard/bye.pcm /sdcard/test_wakeup.pcm \""103 os.system(cpbye)104 os.system(amcommand)105 time.sleep(3)106 checklogsleep="adb "+ sn + "shell \"cat /sdcard/yuyinchangshouge.log |grep paramJasonStr\""107 sleepoutput = os.popen(checklogsleep)108 res= sleepoutput.read() 109 print "sleep logcat",res110 if 'sleep' in res:111 print 'sleep successful';112 sleep=1113 else:114 print "sleep failed"115 116 time.sleep(1)117 output = os.popen(pslogcat)118 output = output.read()119 if "root" in output:120 str = output.split("root")121 val = str[1]122 val = val.lstrip()123 val = val.split(" ")124 pid = val[0]125 killpid="adb "+ sn +"shell kill -9 "+ pid126 os.system(killpid)127 return True 128 129 ...
standby_wakeup.py
Source: standby_wakeup.py
...37 if time_out_wakeup is None:38 time_out_wakeup = stbt.get_config("standby",39 "time_out_wakeup_fom_deep_standby",40 type_=int)41 assert sc_stbt.test_wakeup(sc_stbt.is_wakeup, time_out_wakeup), \42 ("PROBLEM IN WAKE_UP")43def set_wakeup_from_fake_standby():44 # SET WAKE UP AFTER FAKE_STANDBY45 """46 :param time_out_wakeup: time needed to wake up the STB47 :return: True : if wake up achieved before timeout ends48 False : if wake up not detected , or timeout ends49 """50 sc_stbt.wait(5)51 assert sc_stbt.test_wakeup(sc_stbt.is_wakeup), \52 ("PROBLEM IN WAKE_UP")53def test_set_wakeup(time_out_wakeup=None):54 """55 Funtion:set the STB on wakeup status56 :return: Fail if stb is already wakeup57 """58 sc_stbt.wait(1)59 print "iiiiiiiiiiiiiiiiiiiiiiii"60 assert sc_stbt.test_wakeup(timeout=time_out_wakeup),"WAKEUP ACTION NOT DONE"61###########################################62# #Standby63###########################################64def test_set_standby(time_out_standby=None):65 """66 Funtion:set the STB on standby status67 Precondition: STB should be on wake up to launch this test68 :return: Fail if set_standby() fail69 """70 sc_stbt.wait(1)71 if time_out_standby is None:72 time_out_standby = stbt.get_config("standby",73 "time_out_standby",74 type_=int)...
lab3-02-wakeup.py
Source: lab3-02-wakeup.py
1#!/usr/bin/python2import tester3import sys4import time5def experiment(test):6 test.start_program('./test_wakeup')7 start_time = time.time()8 test.lookA('starting wakeup test', 0);9 test.lookA('initial thread returns from sleep\(NULL\)', 1);10 test.lookA('initial thread returns from sleep\(NONE\)', 1);11 result = test.lookA('wakeup test done', 4);12 if (result < 0):13 return14 end_time = time.time()15 diff_time = end_time - start_time16 if (diff_time <= 6.0):17 print 'ERROR: total run time = ' + str(diff_time) + \18 ' should be greater than 6 seconds'19 else:20 test.add_mark(2)21 if test.wait_until_end():22 test.add_mark(2) 23def main():24 mark = 1025 test = tester.Core('wakeup test', mark)26 print 'running ' + str(test.nr_times) + ' times'27 for i in range(test.nr_times):28 experiment(test)29 test.program.close()30 mark = min(mark, test.get_mark())31 test.reset_mark()32 test.add_mark(mark)33if __name__ == '__main__':34 main()...
Check out the latest blogs from LambdaTest on this topic:
Web applications continue to evolve at an unbelievable pace, and the architecture surrounding web apps get more complicated all of the time. With the growth in complexity of the web application and the development process, web application testing also needs to keep pace with the ever-changing demands.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.
With new-age project development methodologies like Agile and DevOps slowly replacing the old-age waterfall model, the demand for testing is increasing in the industry. Testers are now working together with the developers and automation testing is vastly replacing manual testing in many ways. If you are new to the domain of automation testing, the organization that just hired you, will expect you to be fast, think out of the box, and able to detect bugs or deliver solutions which no one thought of. But with just basic knowledge of testing, how can you be that successful test automation engineer who is different from their predecessors? What are the skills to become a successful automation tester in 2019? Let’s find out.
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!!