How to use get_top_activity_name method in Airtest

Best Python code snippet using Airtest

Color_airtest.py

Source: Color_airtest.py Github

copy

Full Screen

...36agree_bt, terms_link, privacy_link = is_enter_home()37touch(terms_link)38sleep(10)39flag = False40act_name = dev.get_top_activity_name()41try:42 assert_equal(act_name, "com.pixel.art.coloring.by.number/​talefun.cd.sdk.webview.MyWebViewActivity", "服务条款链接是否正常跳出")43except:44 print("跳出失败")45if exists(Template(r"tpl1628653574859.png", record_pos=(-0.314, -0.596), resolution=(1080, 1920))):46 flag = True47try:48 assert_equal(flag, True, "判断是否正常显示服务条款页面")49except:50 print("显示失败")51keyevent('KEYCODE_BACK')52sleep(1)53touch(privacy_link)54sleep(10)55act_name = dev.get_top_activity_name()56flag = False57try:58 assert_equal(act_name, "com.pixel.art.coloring.by.number/​talefun.cd.sdk.webview.MyWebViewActivity", "隐私协议链接是否正常跳出")59except:60 print("跳出失败")61if exists(Template(r"tpl1628653574859.png", record_pos=(-0.314, -0.596), resolution=(1080, 1920))):62 flag = True63try:64 assert_equal(flag, True, "判断是否正常显示服务条款页面")65except:66 print("显示失败")67keyevent('KEYCODE_BACK')68sleep(3)69touch(agree_bt)70sleep(1)71# 进入mypainting72touch(Template(r"tpl1628654205391.png", record_pos=(0.378, 0.822), resolution=(1080, 1920)))73sleep(2)74touch(Template(r"tpl1628654222593.png", record_pos=(-0.43, -0.82), resolution=(1080, 1920)))75sleep(2)76touch(Template(r"tpl1628666829596.png", record_pos=(-0.37, -0.632), resolution=(1080, 1920)))77sleep(1)78try:79 assert_exists(Template(r"tpl1628666871971.png", record_pos=(-0.018, -0.809), resolution=(1080, 1920)), "有奖调查打开成功")80 touch(Template(r"tpl1628654344533.png", record_pos=(-0.407, -0.793), resolution=(1080, 1920)))81 sleep(1)82except Exception as e:83 print("打开失败")84 raise e85touch(Template(r"tpl1628654268937.png", record_pos=(-0.37, -0.313), resolution=(1080, 1920)))86touch(Template(r"tpl1628654287761.png", record_pos=(-0.372, 0.473), resolution=(1080, 1920)))87sleep(1)88touch(Template(r"tpl1628654314042.png", record_pos=(0.294, -0.564), resolution=(1080, 1920)))89touch(Template(r"tpl1628654344533.png", record_pos=(-0.407, -0.793), resolution=(1080, 1920)))90sleep(1)91swipe((500, 1344), (504, 153))92sleep(3)93touch(Template(r"tpl1628664592422.png", record_pos=(-0.373, -0.165), resolution=(1080, 1920)))94sleep(10)95try:96 assert_exists(Template(r"tpl1628664646850.png", record_pos=(-0.002, -0.706), resolution=(1080, 1920)), "FAQ打开成功")97except:98 print("打开失败")99keyevent("KEYCODE_BACK")100sleep(1)101touch(Template(r"tpl1628664735847.png", record_pos=(-0.37, 0.146), resolution=(1080, 1920)))102if exists(Template(r"tpl1628664777138.png", threshold=0.8500000000000001, record_pos=(-0.378, 0.621), resolution=(1080, 1920))):103 touch(Template(r"tpl1628664777138.png", threshold=0.8500000000000001, record_pos=(-0.378, 0.621), resolution=(1080, 1920)))104 sleep(3)105 act_name = dev.get_top_activity_name()106 print(act_name)107 try:108 assert_equal(act_name, "com.google.android.gm/​.ComposeActivityGmailExternal", "邮箱弹出")109 keyevent("KEYCODE_BACK")110 sleep(0.5)111 keyevent("KEYCODE_BACK")112 except Exception as e:113 print("邮箱弹出失败")114 raise e115 116touch(Template(r"tpl1628665851814.png", record_pos=(-0.371, 0.463), resolution=(1080, 1920)))117sleep(10)118flag = False119act_name = dev.get_top_activity_name()120try:121 assert_equal(act_name, "com.pixel.art.coloring.by.number/​talefun.cd.sdk.webview.MyWebViewActivity", "服务条款链接是否正常跳出")122except:123 print("跳出失败")124if exists(Template(r"tpl1628653574859.png", record_pos=(-0.314, -0.596), resolution=(1080, 1920))):125 flag = True126try:127 assert_equal(flag, True, "判断是否正常显示服务条款页面")128except:129 print("显示失败")130keyevent('KEYCODE_BACK')131sleep(1)132touch(Template(r"tpl1628665908967.png", record_pos=(-0.372, 0.621), resolution=(1080, 1920)))133sleep(10)134act_name = dev.get_top_activity_name()135flag = False136try:137 assert_equal(act_name, "com.pixel.art.coloring.by.number/​talefun.cd.sdk.webview.MyWebViewActivity", "隐私协议链接是否正常跳出")138except:139 print("跳出失败")140if exists(Template(r"tpl1628653574859.png", record_pos=(-0.314, -0.596), resolution=(1080, 1920))):141 flag = True142try:143 assert_equal(flag, True, "判断是否正常显示服务条款页面")144except:145 print("显示失败")146keyevent('KEYCODE_BACK')147sleep(1)148touch(Template(r"tpl1628654344533.png", record_pos=(-0.407, -0.793), resolution=(1080, 1920)))...

Full Screen

Full Screen

app_helper.py

Source: app_helper.py Github

copy

Full Screen

...35 pattern = re.compile(r"(.+?)\tdevice")36 for match in pattern.finditer(list_output):37 device_list.append(match.group(1))38 return device_list39def get_top_activity_name(adb_path=None):40 adb_path = init_adb_path(adb_path)41 # simplify results42 output = os.popen(adb_path + " shell dumpsys window windows | grep -E \"mCurrentFocus\"").read()43 pattern = re.compile(r"mCurrentFocus.+?{.+?/​(.+?)}")44 return pattern.search(output).group(1)45def start_activity(package_name, activity_name, adb_path=None, ):46 adb_path = init_adb_path(adb_path)47 os.popen(adb_path + " shell am start -n " + package_name + "/​" + activity_name).read()48 return wait_for_activity_on_top(activity_name, adb_path)49def get_current_view_xml_tree(adb_path=None):50 adb_path = init_adb_path(adb_path)51 # ui dump on phone52 output = os.popen(adb_path + " shell uiautomator dump").read()53 pattern = re.compile(r"to:\s*(.+?.xml)")54 res = pattern.search(output)55 if res is None:56 return None57 xml_path = res.group(1)58 # add extra leading slash to avoid git-bash path issue59 xml_path = "/​" + xml_path60 # copy back to current computer61 # TODO: change this to python temp file62 file_name = str(int(random.random() * RANDOM_RANGE_FOR_FILE)) + ".xml"63 file_path = "./​" + TEMP_FOLDER + "/​" + file_name64 os.popen(adb_path + " pull " + xml_path + " " + file_path).read()65 tree = et.parse(file_path)66 return tree67def parse_bounds_text(bounds):68 p = re.compile(r"\[(\d+),(\d+)\]\[(\d+),(\d+)\]")69 m = p.search(bounds)70 if m is None:71 return None, None, None, None72 return int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4))73def wait_for_activity_on_top(name, adb_path=None):74 adb_path = init_adb_path(adb_path)75 dead_counter = 2076 while get_top_activity_name(adb_path) != name:77 time.sleep(1)78 dead_counter -= 179 if dead_counter == 0:80 print("ERROR: Dead loop, couldn't get correct top activity (current: "81 + get_top_activity_name(adb_path) + ")")82 return False83 print("Not activity - \"" + name + "\"is on top")84 return True85def click_on_screen(min_x, min_y, max_x, max_y, adb_path=None):86 adb_path = init_adb_path(adb_path)87 mid_x = (min_x + max_x) /​/​ 288 mid_y = (min_y + max_y) /​/​ 289 os.popen(adb_path + " shell input tap " + str(mid_x) + " " + str(mid_y)).read()90 return91def scroll_on_screen(from_x, from_y, to_x, to_y, adb_path=None):92 adb_path = init_adb_path(adb_path)93 return94# testing codes, remove them in production level95print(repr(get_device_list()))96print(get_top_activity_name())...

Full Screen

Full Screen

runtime.py

Source: runtime.py Github

copy

Full Screen

...15 if m:16 return (m.group(1), m.group(2), m.group(3))17 else:18 return None19 def get_top_activity_name(self):20 """21 Get the top activity name22 Returns:23 package, activity and pid24 """25 tanp = self.get_top_activity_name_and_pid()26 if tanp:27 return tanp[0] + '/​' + tanp[1]28 else:29 return None30 @property31 def name(self):32 return self._name33 ...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

QA’s and Unit Testing – Can QA Create Effective Unit Tests

Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.

LIVE With Automation Testing For OTT Streaming Devices ????

People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.

Why Agile Is Great for Your Business

Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.

Options for Manual Test Case Development & Management

The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.

Test strategy and how to communicate it

I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.

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