def android_aapt_install(): print( WindowsOsUtil.get_command_output(' '.join( ('adb push', GlobalParam.get_aapt_path(), '/data/local/tmp')))) print( WindowsOsUtil.get_command_output( 'adb shell chmod 0755 /data/local/tmp/aapt-arm-pie'))
def setup_params(self): self.processIsRunning = 'python.exe' self.processNotRunning = 'retroarch.exe' self.processToTestRunAndKill = 'notepad.exe' self.command = 'echo 123' yield if WindowsOsUtil.check_process_running(self.processToTestRunAndKill): WindowsOsUtil.kill_process_by_name(self.processToTestRunAndKill)
def android_all_package_list(): msg = filter( None, WindowsOsUtil.get_shell_output(['adb', 'shell'], 'pm list packages -3 -f').split('\r\n')) package_list = [] for ms in msg: ms = android_aapt_get_app_info( ms[ms.index('/'):ms.rindex('=')]).replace('\r\n', '').split('\'') if ms.count('package: name=') == 1: pkg = ms[ms.index('package: name=') + 1] else: pkg = '' if ms.count('application-label-zh-CN:') == 1: name = ms[ms.index('application-label-zh-CN:') + 1] elif ms.count('application-label:') == 1: name = ms[ms.index('application-label:') + 1] elif ms.count('application: label=') == 1: name = ms[ms.index('application: label=') + 1] else: name = 'no label name' if ms.count('launchable-activity: name=') == 1: launch = ms[ms.index('launchable-activity: name=') + 1] else: launch = android_search_app_activity(pkg) package_list.append(','.join((pkg, name, launch))) write_string_to_file( GlobalParam.get_android_apk_list().replace( 'android_apk_list', android_product_info() + '_android_apk_list'), package_list, 'utf8') return package_list
def android_search_app_activity(app_package): cmd = ' '.join(('cmd package resolve-activity', app_package, '|grep name')) msg = (WindowsOsUtil.get_shell_output(['adb', 'shell'], cmd)) if msg == '': msg = 'no activity info' else: msg = msg.replace('\r\n', '').split('name=')[1].strip() return msg
def android_check_app_active(app_package): msg = WindowsOsUtil.get_shell_output( ['adb', 'shell'], 'dumpsys window windows | grep -e \'Window #\'').split('\r\n') for m in msg: if m.__contains__(app_package): msg = StringUtils.split_string_by_regex('{|}', m.strip())[1].split(' ')[2] return msg.split('/')[0], msg.split('/')[1] return 'not_find', 'not_find'
def test_kill_and_run_process_by_name(self): warnings.simplefilter('ignore', ResourceWarning) WindowsOsUtil.run_process_by_name(self.processToTestRunAndKill) self.assertTrue(WindowsOsUtil.check_process_running(self.processToTestRunAndKill)) WindowsOsUtil.kill_process_by_name(self.processToTestRunAndKill) self.assertFalse(WindowsOsUtil.check_process_running(self.processToTestRunAndKill))
def test_kill_and_run_process_by_name(self): WindowsOsUtil.run_process_by_name(self.processToTestRunAndKill) assert WindowsOsUtil.check_process_running( self.processToTestRunAndKill) WindowsOsUtil.kill_process_by_name(self.processToTestRunAndKill) assert not WindowsOsUtil.check_process_running( self.processToTestRunAndKill)
def android_current_opened_app_info(): adb_dumpsys_window_msg = WindowsOsUtil.get_shell_output( ['adb', 'shell'], 'dumpsys window windows') msg_split_one = '' msg_split_two = '' if adb_dumpsys_window_msg.__contains__('mCurrentFocus'): msg = WindowsOsUtil.get_shell_output( ['adb', 'shell'], 'dumpsys window windows | grep -E \'mCurrentFocus|mFocusedApp\'') msg = StringUtils.split_string_by_regex('{|}', msg)[1].split(' ')[2] msg_split_one = msg.split('/')[0] msg_split_two = msg.split('/')[1] elif adb_dumpsys_window_msg.__contains__('mSurface'): msg = WindowsOsUtil.get_shell_output( ['adb', 'shell'], 'dumpsys window windows | grep -E \'mSurface=Surface\'') msg = re.findall( 'mSurface=Surface\\(name=' + '(.+?)' + '/' + '(.+?)' + '\\)/@', msg) msg_split_one = msg.__getitem__(0)[0] msg_split_two = msg.__getitem__(0)[1] return msg_split_one, msg_split_two
def android_aapt_get_app_info(app_path): cmd = ' '.join( ('/data/local/tmp/aapt-arm-pie d badging', app_path, '|grep -E', '\'package|launchable-activity|application-label\'')) msg = (WindowsOsUtil.get_shell_output(['adb', 'shell'], cmd)) return msg
def android_api_version(): return WindowsOsUtil.get_command_output( 'adb shell getprop ro.build.version.sdk')
def android_find_app_user_id(app_package): cmd = ''.join(('dumpsys package ', app_package, ' | grep userId')) msg = WindowsOsUtil.get_shell_output(['adb', 'shell'], cmd) return msg
def android_backup_app_apk(app_package, backup_path): cmd = ''.join(('pm path ', app_package)) msg = WindowsOsUtil.get_shell_output(['adb', 'shell'], cmd) cmd = ''.join(('adb pull ', msg.replace('package:', '').strip(), ' ', backup_path)) WindowsOsUtil.get_command_output(cmd)
def test_get_shell_output(self): assert '123' == WindowsOsUtil.get_shell_output(['powershell'], self.command)
def android_check_screen_is_locked(): cmd = 'dumpsys window | grep mDreamingLockscreen' msg = (WindowsOsUtil.get_shell_output(['adb', 'shell'], cmd)) return msg.__contains__('mDreamingLockscreen=true')
def android_device_list(): return WindowsOsUtil.get_command_output('adb devices').split( '\n')[1].replace('device', '').strip()
def test_get_command_output(self): assert '123' == WindowsOsUtil.get_command_output(self.command)
def android_home_button(): WindowsOsUtil.get_shell_output([ 'adb', 'shell' ], 'am start -W -c android.intent.category.HOME -a android.intent.action.MAIN' )
def test_get_command_output(self): self.assertEqual('123', WindowsOsUtil.get_command_output(self.command))
def test_check_process_running(self): with self.subTest(): self.assertTrue(WindowsOsUtil.check_process_running(self.processIsRunning)) with self.subTest(): self.assertFalse(WindowsOsUtil.check_process_running(self.processNotRunning))
from selenium.common.exceptions import NoAlertPresentException from selenium.common.exceptions import TimeoutException from file_and_system.file_utils import write_binary_to_file from file_and_system.windows_os_utils import WindowsOsUtil from python_common.global_param import GlobalParam from selenium_test.selenium_utils import * WindowsOsUtil.kill_process_by_name('MicrosoftWebDriver.exe') driver = init_driver('edge', GlobalParam.get_edge_driver_path()) open_browser_single_tab(driver, 'https://www.12306.cn/index/') # wait dom return complete state wait_for_page_full_loaded(driver) loading_element = find_element_by_xpath(driver, '//div[@id="page-loading"]') wait_for_element_disappeared(driver, loading_element) try: wait_for_element_to_be_clickable(driver, '//a[text()="登录"]') wait_for_page_full_loaded(driver) wait_for_element_to_be_clickable(driver, '//a[text()="账号登录"]') # get captcha picture img_text = find_element_by_xpath(driver, '//img[@id="J-loginImg"]').get_attribute( 'src')[len('data:image/jpg;base64,'):] write_binary_to_file(GlobalParam.get_image_input(), img_text) find_element_by_xpath(driver, '//input[@id="J-userName"]').send_keys('username') find_element_by_xpath(driver, '//input[@id="J-password"]').send_keys('password')
def tearDownClass(cls): if WindowsOsUtil.check_process_running(cls.processToTestRunAndKill): WindowsOsUtil.kill_process_by_name(cls.processToTestRunAndKill)
def test_get_shell_output(self): self.assertEqual('123', WindowsOsUtil.get_shell_output(['powershell'], self.command))
def test_check_process_running(self): assert WindowsOsUtil.check_process_running(self.processIsRunning) assert not WindowsOsUtil.check_process_running(self.processNotRunning)
def android_product_info(): return WindowsOsUtil.get_command_output( 'adb shell getprop ro.product.model')
from file_and_system.windows_os_utils import WindowsOsUtil from selenium_test.selenium_utils import init_driver, open_browser_single_tab from python_common.global_param import GlobalParam WindowsOsUtil.kill_process_by_name('MicrosoftWebDriver.exe') WindowsOsUtil.kill_process_by_name('chromedriver.exe') WindowsOsUtil.kill_process_by_name('IEDriverServer.exe') chrome_driver = init_driver('chrome', GlobalParam.get_chrome_driver_path()) open_browser_single_tab(chrome_driver,'https://www.baidu.com') chrome_driver.quit() edge_driver = init_driver('edge', GlobalParam.get_edge_driver_path()) open_browser_single_tab(edge_driver,'https://www.baidu.com') edge_driver.quit() ie_driver = init_driver('ie', GlobalParam.get_ie_driver_path()) open_browser_single_tab(ie_driver,'https://www.baidu.com') ie_driver.quit()