コード例 #1
0
 def desired_setting(self, i):
     self.WF = WriteUserCommand()
     udid = self.WF.get_value('user_info_' + str(i), 'deviceName')
     port = self.WF.get_value('user_info_' + str(i), 'port')
     desired_caps = {
         # udid adb devices
         "platformName": "Android",
         "platformVersion": "8.1.0",
         "deviceName": "android",
         "udid": udid,
         "noReset": 'true',  # 不重复安装APP
         "appActivity":
         "com.desaysv.dsvsettings.MainActivity",  # 20200224 Mei Xiu,设置app activity名称
         "appPackage":
         "com.desaysv.dsvsettings",  # 20200224 Mei Xiu 设置app包名
         'newCommandTimeout': '300',
         # "automationName":"UIAutomator2"
     }
     driver = webdriver.Remote("http://127.0.0.1:" + port + "/wd/hub",
                               desired_caps)  # python运行时会跳转到app界面
     log.logging.info('APP界面初始化成功!')
     time.sleep(10)
     return driver
コード例 #2
0
ファイル: test_case.py プロジェクト: WanlinLi798/android_test
def get_count():
    write_user_file = WriteUserCommand()
    count = write_user_file.get_file_lines()
    return count
コード例 #3
0
ファイル: server.py プロジェクト: WanlinLi798/android_test
 def __init__(self):
     self.dos = DosCmd()
     self.device_list = self.get_device()
     self.wf = WriteUserCommand()
コード例 #4
0
ファイル: server.py プロジェクト: WanlinLi798/android_test
class Server:
    def __init__(self):
        self.dos = DosCmd()
        self.device_list = self.get_device()
        self.wf = WriteUserCommand()

    def get_device(self):
        devices_list = []
        result_list = self.dos.excute_cmd_result('adb devices')
        #         print result_list
        if len(result_list) >= 2:
            for i in result_list:
                if 'List' in i:
                    continue
                devices_info = i.split('\t')
                if devices_info[1] == 'device':
                    devices_list.append(devices_info[0])
            return devices_list
        else:
            return None

    def create_port_list(self, start_port):
        '''
        创建可用端口
        '''
        port = Port()
        port_list = []
        port_list = port.create_port_list(start_port, self.device_list)
        return port_list

    def create_command_list(self, i):
        #appium -p 4723 -bp 4724 -U 00001234
        command_list = []
        appium_port_list = self.create_port_list(4000)
        bootstrap_port_list = self.create_port_list(4900)
        device_list = self.device_list
        command = "appium -p " + str(appium_port_list[i]) + " -bp " + str(
            bootstrap_port_list[i]
        ) + " -U " + device_list[i] + " --no-reset --session-override"
        #appium -p 4723 -bp 4726 -U 127.0.0.1:62001 --no-reset --session-override --log E:/Teacher/Imooc/AppiumPython/log/test01.log
        command_list.append(command)
        self.wf.write_data(i, device_list[i], str(bootstrap_port_list[i]),
                           str(appium_port_list[i]))

        return command_list

    def start_server(self, i):
        self.start_list = self.create_command_list(i)
        print(self.start_list)
        self.dos.excute_cmd(self.start_list[0])

    def kill_server(self):
        command = 'tasklist | find "node.exe"'
        server_list = self.dos.excute_cmd_result(command)
        if len(server_list) > 0:
            self.dos.excute_cmd('taskkill -F -PID node.exe')

    def main(self):
        thread_list = []
        self.kill_server()
        self.wf.clear_data()
        for i in range(len(self.device_list)):
            appium_start = threading.Thread(target=self.start_server,
                                            args=(i, ))
            thread_list.append(appium_start)
        for j in thread_list:
            j.start()
        time.sleep(25)
コード例 #5
0
 def __init__(self, i):
     self.handle = SourceHandle(i)
     self.WF = WriteUserCommand()
     self.udid = self.WF.get_value('user_info_' + str(i), 'deviceName')
コード例 #6
0
class SourceBusiness:
    def __init__(self, i):
        self.handle = SourceHandle(i)
        self.WF = WriteUserCommand()
        self.udid = self.WF.get_value('user_info_' + str(i), 'deviceName')

    def BT_switch(self):
        try:
            self.handle.home()
            time.sleep(1)
            #             udid = self.WF.get_value('user_info_'+str(i),'deviceName')
            os.system('adb -s ' + self.udid + ' shell input tap 404 648')
            #             os.system('adb -s 00001234 shell input tap 404 648')
            print(11111)
            self.handle.music_hall()
            self.handle.BT()
            time.sleep(5)
        except Exception:
            return False
            pass

    def USB_audio_switch(self):
        try:
            #             self.handle.home()
            #             os.system('adb -s 00001234 shell input tap 640 563')
            # #             self.handle.menu()
            #             self.handle.player()
            #             udid = self.WF.get_value('user_info_'+str(i),'deviceName')
            os.system('adb -s ' + self.udid + ' shell input tap 404 648')
            #             os.system('adb -s 00001234 shell input tap 404 648')
            self.handle.music_hall()
            self.handle.USB_audio()
        except Exception:
            return False
            pass

    def local_music(self):
        self.handle.my_icon()
        self.handle.local_music()

    def go_find(self):
        self.handle.back()
        self.handle.find()

    def factory_reset(self):
        self.handle.home()
        time.sleep(5)
        #         udid = self.WF.get_value('user_info_'+str(0),'deviceName')
        os.system('adb -s ' + self.udid + ' shell input tap 640 563')
        print('进入设置界面')
        time.sleep(1)
        self.handle.setting()
        print('恢复出厂设置')
        self.handle.system()
        self.handle.factory_reset()
        self.handle.confirm()
        time.sleep(30)

    def sendPW(self):

        self.handle.enter_pw('12345678')
        self.handle.pw_confirm()

    def backhome(self):
        self.handle.home()
コード例 #7
0
class ActionMethod():
    
    def __init__(self):
        base_driver = BaseDriver()
        self.driver = base_driver.desired_setting(0)
        self.WebDriverWait = WebDriverWait
        self.EC = EC
        self.By = By
        self.get = GetByLocal(self.driver, self.WebDriverWait, self.EC, self.By)
        self.WF = WriteUserCommand()
        self.read = ReadIni()
              
    def click(self, *args):
        try:
            log.logging.info('开始点击'+str(args[0]))
            element = self.get.get_element(args[0])
            element.click()
        except Exception:
          # if element == None:
            log.logging.info(str('Fail:  '+args[0])+'元素没有找到......')
            tm = time.strftime("%Y%m%d_%H%M%S")
            path1 = os.path.join(path, tm+args[0]+'.png')
            self.driver.get_screenshot_as_file(path1)
            quit()
#         element.click()

    def sound_check(self, n):
        creat_filename = open(self.read.get_value('key', 'write_labview_log'), 'w')
        creat_filename.write(str(n))
        creat_filename.flush()
        time.sleep(2)
        creat_filename.close()
        p = subprocess.Popen(r'sound_check.exe')
        p.wait()
        with open('Soundresult.txt', 'r') as f:
            lines = f.readlines()
            n = 0
            while(1):
                n += 1
                a_str = "".join(lines[-n:])
                if a_str.strip() != '':
                    break
            if 'OK' in a_str:
                print('666')
                return a_str
            else:
                print('777')
                return None

    def click_home(self):
        self.driver.keyevent(3)
        
    def click_menu(self):
        udid = self.WF.get_value('user_info_'+str(0), 'deviceName')
        os.system('adb -s '+udid+' shell input tap 640 563')
        
    def swipe_to_setting(self):
        udid = self.WF.get_value('user_info_'+str(0), 'deviceName')
        os.system('adb -s '+udid+' shell input swipe 931 669 400 669 1000')
        time.sleep(2)
        os.system('adb -s '+udid+' shell input swipe 931 669 400 669 1000')
        time.sleep(2)
        os.system('adb -s '+udid+' shell input tap 334 663')
        
    def repeat_ab(self, a, b):
        pass
        
    def sleep(self, *args):
        time.sleep(int(args[0]))
        
    def click_player(self):
        udid = self.WF.get_value('user_info_'+str(0), 'deviceName')
        os.system('adb -s '+udid+' shell input tap 404 648')
        # os.system('adb -s 00001234 shell input tap 404 648')

    def get_size(self):
        size = self.driver.get_window_size()
        width = size['width']
        height = size['height']
        return width, height

    def swipe_down(self):
        udid = self.WF.get_value('user_info_'+str(0), 'deviceName')
        # x1 = self.get_size()[0]/2
        # y1 = self.get_size()[1]/10
        # y = self.get_size()[1]/10*9
        os.system('adb -s '+udid+' shell input swipe 612 180 612 481 100')
        # self.driver.swipe(x1,y1,x1,y,int(s))
        
    def swipe_up(self, s1):
        x1 = self.get_size()[0]/2
        y = self.get_size()[1]/10
        y1 = self.get_size()[1]/10*7
        self.driver.swipe(x1, y1, x1, y, int(s1))

    def get_element(self, *args):
        return self.get.get_element(args[0])
    
    def check(self, *args):
        try:
            element = self.get.get_element(args[0])   # 获取界面元素ID
            return element
        except :
            # if element == None:
            print('元素没有找到......')
            tm = time.strftime("%Y%m%d_%H%M%S")
            path1 = os.path.join(path, tm+args[0]+'.png')

            self.driver.get_screenshot_as_file(path1)
            # quit()    # Mei Xiu 20200225注释,不注释会导致后面Case不执行

    def picture_match(self, pic, row):
        tm = time.strftime("%Y%m%d_%H%M%S")
        PIC = cv2.imread(path + pic +".png")
        self.driver.get_screenshot_as_file('file.png')
        match = cv2.imread('file.png')
        
        grayA = cv2.cvtColor(PIC, cv2.COLOR_BGR2GRAY)
        grayB = cv2.cvtColor(match, cv2.COLOR_BGR2GRAY)
    
        (score, diff) = compare_ssim(grayA, grayB, full=True)
        print("SSIM: {}".format(score))
        if score < 0.95:
            os.rename(os.path.join(os.getcwd(), 'file.png'), os.path.join(path, tm+str(row)+".png"))
            return None
        return score

#         h1 = PIC.histogram()
#         h2 = match.histogram()
#         differ = math.sqrt(reduce(operator.add, list(map(lambda a,b: (a-b)**2, h1, h2)))/len(h1))
#         if differ > 1000:
#             os.rename(os.path.join(os.getcwd(),'file.png'),os.path.join(path,tm+str(row)+".png"))
#             return None
#         return differ
        
    def ROI_picture_match(self, pic, row):
        tm = time.strftime("%Y%m%d_%H%M%S")
        image_path = path + "/screenshot/" + pic + ".png"
        srcImg = cv2.imread(image_path)
        self.driver.get_screenshot_as_file('filename.png')
        match = cv2.imread('filename.png')
        
        with open(InitParam().roi_yaml_filepath) as f:
            data = yaml.load(f) 
            roi = data['key'+pic]
        img_roi = srcImg[roi['iy']:(roi['iy']+roi['y']), roi['ix']:(roi['ix']+roi['x'])]
        match_roi = match[roi['iy']:(roi['iy']+roi['y']), roi['ix']:(roi['ix']+roi['x'])]
        cv2.imwrite(os.getcwd()+"/img_roi.png", img_roi)
        cv2.imwrite(os.getcwd()+"/match_roi.png", match_roi)
        PIC_roi = cv2.imread(os.getcwd()+"/img_roi.png")
        match_roi = cv2.imread(os.getcwd()+"/match_roi.png")
        grayA = cv2.cvtColor(PIC_roi, cv2.COLOR_BGR2GRAY)
        grayB = cv2.cvtColor(match_roi, cv2.COLOR_BGR2GRAY)
    
        (score, diff) = compare_ssim(grayA, grayB, full=True)
        print("SSIM: {}".format(score))
        if score < 0.95:
            os.rename(os.path.join(os.getcwd(),'filename.png'),os.path.join(path,tm+str(row)+".png"))
            return None
        return score
#         h1 = PIC_roi.histogram()
#         h2 = match_roi.histogram()
#         differ = math.sqrt(reduce(operator.add, list(map(lambda a,b: (a-b)**2, h1, h2)))/len(h1))
#         print differ
#         if differ > 0.1:
#             os.rename(os.path.join(os.getcwd(),'filename.png'),os.path.join(path,tm+str(row)+".png"))
#             print differ
#             quit()
#             return None
#         return h2            
    
    def camara_macth(self, pic, row):
        tm = time.strftime("%Y%m%d_%H%M%S")
        PIC = cv2.imread(os.getcwd()+"/"+pic+".png")
        self.driver.get_screenshot_as_file('file.png')
        match =  cv2.imread('file.png')
        grayA = cv2.cvtColor(PIC, cv2.COLOR_BGR2GRAY)
        grayB = cv2.cvtColor(match, cv2.COLOR_BGR2GRAY)
    
        (score, diff) = compare_ssim(grayA, grayB, full=True)
        print("SSIM: {}".format(score))
        if score < 0.95:
            os.rename(os.path.join(os.getcwd(), 'file.png'), os.path.join(path, tm+str(row)+".png"))
            return None
        return score