class Test(unittest.TestCase):
    #初始化环境
    def setUp(self):
        desired_caps = {
            'platformName': 'Android',
            'deviceName': 'Mi6',
            'platformVersion': '8.0.0',
            #apk包名
            'appPackage': 'com.etnet.android.iq',
            #apk的launcherActivity
            'appActivity': '.MainActivity'
        }

        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

        self.extend = Appium_Extend(self.driver)

        #回到主屏幕
        # self.driver.press_keycode(3)
        self.swipe = Swipe(self.driver)

    def close_ad(self):
        time.sleep(3)
        close_btn = self.driver.find_element_by_id("com.etnet.android.iq:id/close_btn")
        if close_btn:
            close_btn.click()  
    #退出测试
    def tearDown(self):
        self.driver.quit()

    def test_get_screen_by_elements(self):
        self.close_ad()
        elements = self.driver.find_elements_by_class_name("android.view.View")
        self.extend.get_screenshot_by_elements(elements)

    def test_get_screen_by_custom(self):
        self.close_ad()
        time.sleep(3)
        scrollview = self.driver.find_element_by_id("com.etnet.android.iq:id/ScrollView")
           
        print(self.driver.get_window_rect())
        self.extend.get_screenshot_by_scroll(scrollview)
        element = self.driver.find_element_by_id("android:id/statusBarBackground")
        size = element.size

        # self.extend.get_screenshot_by_custom_size(0, size["height"], size["width"], 1920-60-160)
        self.swipe.swipeUp(1000, 4)
        # self.extend.get_screenshot_by_custom_size(0, size["height"], size["width"], 1920-60-160)

    def test_same_as(self):
        element = self.driver.find_elements_by_class_name("android.view.View")

        load = self.extend.load_image("f:\\screen\\image.png")
        #要求百分百相似
        result = self.extend.get_screenshot_by_element(element).same_as(load, 0)
        self.assertTrue(result)
class Test(unittest.TestCase):
    #初始化环境
    def setUp(self):
        desired_caps = {}
        desired_caps["platformName"] = "Android"
        desired_caps["platformVersion"] = "4.3"
        desired_caps["deviceName"] = "3a11d697"
        desired_caps["appPackage"] = "com.yuntongxun.rongxin.lite"
        desired_caps[
            "appActivity"] = "com.yuntongxun.rongxin.lite.permission.RECEIVE_MSG"
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",
                                       desired_caps)

        self.extend = Appium_Extend(self.driver)

        #回到主屏幕
        self.driver.press_keycode(3)

    #退出测试
    def tearDown(self):
        self.driver.quit()

    def test_get_screen_by_element(self):
        element = self.driver.find_element_by_id(
            "com.yuntongxun.rongxin.lite:id/verifyCodePic")

        self.extend.get_screenshot_by_element(element).write_to_file(
            "f:\\screen", "image")
        self.assertTrue(os.path.isfile("f:\\screen\\image.png"))

    def test_same_as(self):
        element = self.driver.find_element_by_id(
            "com.yuntongxun.rongxin.lite:id/verifyCodePic")

        load = self.extend.load_image("f:\\screen\\image.png")
        #要求百分百相似
        result = self.extend.get_screenshot_by_element(element).same_as(
            load, 0)
        self.assertTrue(result)
Beispiel #3
0
class Imtest(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['deviceName'] = '3a11d697'
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '5.1.1'
        #desired_caps['unicodeKeyboard'] = "true"#使用 Unicode 输入法。默认值false
        #desired_caps['resetKeyboard'] = "true"#在设定了 unicodeKeyboard 关键字的 Unicode 测试结束后,重置输入法到原有状态。如果单独使用,将会被忽略。默认值 false
        desired_caps['appPackage'] = 'com.yuntongxun.ecdemo'
        desired_caps[
            'appActivity'] = 'com.yuntongxun.ecdemo.ui.LauncherActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub',
                                       desired_caps)
        self.verificationErrors = []
        self.driver.implicitly_wait(30)
        self.extend = Appium_Extend(self.driver)

    def test_get_screen_by_element(self):
        element = self.driver.find_element_by_id("chatting_content_iv")
        self.extend.get_screenshot_by_element(element).write_to_file(
            "f:\\screen", "image1")
        #assert_true(os.path.isfile("f:\\screen\\image1.jpg"))

    def test_same_as(self):
        element = self.driver.find_element_by_id(
            "chatting_content_iv")  #chatting_content_iv
        load = self.extend.load_image("f:\\screen\\image1.jpg")
        #要求百分百相似
        result = self.extend.get_screenshot_by_element(element).same_as(
            load, 0)
        assert_true(result)

    def test_send_picture(self):
        '''发送图片'''
        time.sleep(5)
        swip.swipLeft(self, 500)  #左划
        time.sleep(2)
        self.driver.find_element_by_id(
            "com.yuntongxun.ecdemo:id/card_item_tv").click()
        self.driver.find_element_by_id("content").click()
        self.driver.find_element_by_id("content").send_keys("13311267857")
        self.driver.find_element_by_id("text_right").click()

        #发送图片
        self.driver.find_element_by_id("chatting_attach_btn").click()
        self.driver.find_element_by_id("app_grid_item_icon_mask").click()
        self.driver.find_element_by_id("imageview_photo").click()
        self.driver.find_element_by_id("text_right").click()
        time.sleep(2)
        self.test_get_screen_by_element()  #获取图片保存到本地
        #删除发送的图片
        el = self.driver.find_element_by_id("tv_read_unread")  #状态
        action1 = TouchAction(self.driver)
        action1.long_press(el, duration=5000).perform()
        self.driver.find_element_by_name(u"删除").click()
        self.driver.find_element_by_id("dilaog_button3").click()  #确认删除

        time.sleep(2)
        self.test_same_as()

        #接收到的图片对比发送的图片
        #self.test_get_screen_by_element()#获取接收到的图片保存到本地
        print u"接收图片成功"

        x1 = self.driver.find_element_by_id(
            "chatting_content_iv").location.get('x')
        y1 = self.driver.find_element_by_id(
            "chatting_content_iv").location.get('y')
        print x1, y1
        x1 = int(x1) + 400
        y1 = int(y1) + 100
        print x1, y1

        self.driver.tap([(x1, y1)], 5000)
        self.driver.find_element_by_name(u"删除").click()
        self.driver.find_element_by_id("dilaog_button3").click()  #确认删除

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
Beispiel #4
0
class Imtest(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['deviceName'] = '3a11d697'
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '5.1.1'
        #desired_caps['unicodeKeyboard'] = "true"#使用 Unicode 输入法。默认值false
        #desired_caps['resetKeyboard'] = "true"#在设定了 unicodeKeyboard 关键字的 Unicode 测试结束后,重置输入法到原有状态。如果单独使用,将会被忽略。默认值 false
        desired_caps['appPackage'] = 'com.yuntongxun.ecdemo'
        desired_caps[
            'appActivity'] = 'com.yuntongxun.ecdemo.ui.LauncherActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub',
                                       desired_caps)
        self.verificationErrors = []
        self.driver.implicitly_wait(30)
        self.extend = Appium_Extend(self.driver)
        #获得机器屏幕大小x,y
        x = self.driver.get_window_size()['width']
        y = self.driver.get_window_size()['height']
        l = [x, y]
        print l
        with open('F:\Appium\size\size.txt', 'w') as f:
            for i in range(len(l)):
                f.write(str(l[i]) + '\n')
            f.close()

    #屏幕向上滑动
    def swipeUp(self, t):
        with open('F:\Appium\size\size.txt', 'r') as f:
            l = f.readlines()
            for i in range(len(l)):
                l[i] = int(l[i][:len(l[i]) - 1])
        x1 = int(l[0] * 0.5)  #x坐标
        y1 = int(l[1] * 0.75)  #起始y坐标
        y2 = int(l[1] * 0.25)  #终点y坐标
        self.driver.swipe(x1, y1, x1, y2, t)

    def swipLeft(self, t):
        #l=[1080,1980]
        with open('F:\Appium\size\size.txt', 'r') as f:
            l = f.readlines()
            for i in range(len(l)):
                l[i] = int(l[i][:len(l[i]) - 1])
        x1 = int(l[0] * 0.75)
        y1 = int(l[1] * 0.5)
        x2 = int(l[0] * 0.05)
        print[x1, y1, x2, y1]
        self.driver.swipe(x1, y1, x2, y1, t)

    def test_get_screen_by_element(self):
        element = self.driver.find_element_by_id("chatting_content_iv")
        self.extend.get_screenshot_by_element(element).write_to_file(
            "f:\\screen", "image1")
        #assert_true(os.path.isfile("f:\\screen\\image1.jpg"))

    def test_same_as(self):
        element = self.driver.find_element_by_id("chatting_content_iv")
        load = self.extend.load_image("f:\\screen\\image1.jpg")
        #要求百分百相似
        result = self.extend.get_screenshot_by_element(element).same_as(
            load, 0)
        assert_true(result)

    def test_send_picture(self):
        '''发送图片'''
        login.test_login(self, el="13311267857")
        self.driver.find_element_by_name("https://www.baidu.com").click()
        el = self.driver.find_element_by_id("tv_read_unread").get_attribute(
            "text")
        assert_equal(el, u"已读", msg=u"阅读状态验证失败")
        print el + u" 阅读状态验证成功"
        el = self.driver.find_element_by_id("chatting_content_itv")
        action1 = TouchAction(self.driver)
        action1.long_press(el, duration=5000).perform()
        self.driver.find_element_by_name(u"删除").click()
        self.driver.find_element_by_id("dilaog_button3").click()  #确认删除
        self.driver.press_keycode('4')  #点击返回键
        self.swipLeft(500)
        self.driver.find_element_by_name("13366778604").click()
        self.driver.find_element_by_id("entrance_chat").click()
        #发送图片
        self.driver.find_element_by_id("chatting_attach_btn").click()
        self.driver.find_element_by_id("app_grid_item_icon_mask").click()
        self.driver.find_element_by_id("imageview_photo").click()
        self.driver.find_element_by_id("text_right").click()

        #self.test_get_screen_by_element()#获取发送的图片保存到本地

        self.driver.press_keycode('4')  #点击返回键
        #self.driver.find_element_by_id("chatting_content_itv").click()
        time.sleep(2)
        logout.test_logout(self)  #退出登录
        login.test_login(self, el="13366778604")  #使用账号receive登录

        time.sleep(2)
        self.driver.find_element_by_name("13311267857").click()
        #接收到的图片对比发送的图片
        self.test_get_screen_by_element()  #获取发送的图片保存到本地
        self.test_same_as()
        time.sleep(2)
        print u"接收图片成功"

        x1 = self.driver.find_element_by_id(
            "chatting_content_iv").location.get('x')
        y1 = self.driver.find_element_by_id(
            "chatting_content_iv").location.get('y')
        print x1, y1
        x1 = int(x1) + 400
        y1 = int(y1) + 100
        print x1, y1

        self.driver.tap([(x1, y1)], 5000)
        self.driver.find_element_by_name(u"删除").click()
        self.driver.find_element_by_id("dilaog_button3").click()  #确认删除

        self.driver.press_keycode('4')  #点击返回键
        logout.test_logout(self)  #退出登录

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
Beispiel #5
0
class ElementCheck(object):
    def __init__(self, tester, driver):
        unittest.TestCase()
        self.tester = tester
        self.driver = driver
        self.Extend = Appium_Extend(driver)

    #等待元素超过多久报错,默认5S
    def wait_element(self, how, element, times=5):
        global validate
        global event
        global deadline
        deadline = 0
        while True:
            try:
                if how == 'id':
                    event = self.driver.find_element_by_id(element)
                elif how == 'name':
                    event = self.driver.find_element_by_name(element)
                elif how == 'class':
                    event = self.driver.find_element_by_class_name(element)
                elif how == 'xpath':
                    event = self.driver.find_element_by_xpath(element)
                elif how == 'classes':
                    element = element.split('[')
                    event = self.driver.find_elements_by_class_name(element[0])
                    event = event[int(element[1].split(']')[0])]
                elif how == 'ides':
                    element = element.split('[')
                    event = self.driver.find_elements_by_id(element[0])
                    event = event[int(element[1].split(']')[0])]
                validate = True
                print('找到元素,不进行等待')
                break
            except:
                time.sleep(1)
                deadline += 1
                if deadline <= times:
                    #print('等待',deadline,'秒')
                    continue
                else:
                    #如果找不到元素进行截图,截图是按照当时时间来命名
                    #判断如果没有指定失败图片且,同文件夹的名字为Fail_picture的文件夹新建一个
                    try:
                        os._exists(r'./Fail_picture') == False
                        os.mkdir(r'./Fail_picture')
                    except:
                        pass
                    #设置时间格式
                    ISOTIMEFORMAT = '%Y%m%d_%X'
                    localtime = str(
                        time.strftime(ISOTIMEFORMAT,
                                      time.localtime())).replace(':', '')
                    print('未找到要点击的元素页面截图为:', localtime)
                    #以时间命名截屏
                    self.driver.get_screenshot_as_file('./Fail_picture/' +
                                                       localtime + '.png')
                    #assert event, '没有找到想要获取的元素'
                    print('网络延迟,超过', times, '秒')
                    validate = False
                    break
        assert validate == True, '超过设定等待时间未发现元素' + element
        #返回一个元素
        return event

    #检查是否纯在某元素
    def existence(self, how, element):
        global validate
        global result
        global event
        global time_no
        try:
            if how == 'id':
                event = self.driver.find_element_by_id(element)
            elif how == 'name':
                event = self.driver.find_element_by_name(element)
            elif how == 'class':
                event = self.driver.find_element_by_class_name(element)
            elif how == 'xpath':
                event = self.driver.find_element_by_xpath(element)
            result = True
        except:
            #如果找不到元素进行截图,截图是按照当时时间来命名
            #判断如果没有指定失败图片且,同文件夹的名字为Fail_picture的文件夹新建一个
            try:
                os._exists(r'./Fail_picture') == False
                os.mkdir(r'./Fail_picture')
            except:
                pass
            #设置时间格式
            ISOTIMEFORMAT = '%Y%m%d_%X'
            localtime = str(time.strftime(ISOTIMEFORMAT,
                                          time.localtime())).replace(':', '')
            print('未找到想要获取的元素', element, '页面截图为:', localtime)
            #以时间来命名截屏
            self.driver.get_screenshot_as_file('./Fail_picture/' + localtime +
                                               '.png')
            result = False
        return result

    #等待一类元素超过多久报错,默认5S
    def elements(self, how, element, times=5):
        global validate
        global event
        global deadline
        deadline = 0
        while True:
            try:
                if how == 'id':
                    event = self.driver.find_elements_by_id(element)
                elif how == 'name':
                    event = self.driver.find_elements_by_name(element)
                elif how == 'class':
                    event = self.driver.find_elements_by_class_name(element)
                elif how == 'xpath':
                    event = self.driver.find_elements_by_xpath(element)
                if len(event) > 0:
                    validate = True
                print('找到元素,不进行等待')
                break
            except:
                time.sleep(1)
                deadline += 1
                if deadline <= times:
                    #print('等待',deadline,'秒')
                    continue
                else:
                    #如果找不到元素进行截图,截图是按照当时时间来命名
                    #判断如果没有指定失败图片且,同文件夹的名字为Fail_picture的文件夹新建一个
                    try:
                        os._exists(r'./Fail_picture') == False
                        os.mkdir(r'./Fail_picture')
                    except:
                        pass
                    #设置时间格式
                    ISOTIMEFORMAT = '%Y%m%d_%X'
                    localtime = str(
                        time.strftime(ISOTIMEFORMAT,
                                      time.localtime())).replace(':', '')
                    print('未找到要点击的元素页面截图为:', localtime)
                    #以时间命名截屏
                    self.driver.get_screenshot_as_file('./Fail_picture/' +
                                                       localtime + '.png')
                    #assert event, '没有找到想要获取的元素'
                    print('网络延迟,超过', times, '秒')
                    validate = False
                    break
        assert validate == True, '超过设定等待时间未发现元素' + element
        #返回一个元素
        return event

    #元素检查和截图存放位置
    def click(self, how, element):
        event = self.wait_element(how, element)
        event.click()

    def click_jump(self, how1, element1, how2=0, element2=0):
        global validate
        #点击元素1
        event1 = self.wait_element(how1, element1)
        event1.click()
        time.sleep(1)
        #通过一个元素是否存在对按键进行检验
        try:
            self.wait_element(how2, element2)
            return validate
        except:
            validate = False
        return validate

    #通过元素本身是否变化进行判断元素是否被点击
    def click_change(self, how, element, type='change'):
        #元素检查和截图存放位置
        global validate
        global event
        #截取元素点击前的图片
        event = self.wait_element(how, element)
        self.Extend.get_screenshot_by_element(event).write_to_file(
            './Temp', 'click_before')
        load = self.Extend.load_image('./Temp/click_before.png')
        time.sleep(1)
        print(event)
        self.Extend.get_screenshot_by_element(event).write_to_file(
            './Temp', 'click_before')
        load = self.Extend.load_image('./Temp/click_before.png')
        event.click()
        if type == 'change':
            result = self.Extend.get_screenshot_by_element(event).same_as(
                load, 0)
            if result == False:
                validate = True
            else:
                validate = False
        #hide形式
        else:
            result = self.existence(how, element)
            if result == True:
                print('发现元素', element, '截图看是否一致')
                result_picture = self.Extend.get_screenshot_by_element(
                    event).same_as(load, 0)
                if result_picture == False:
                    validate = True
                else:
                    validate = False
            else:
                print('隐藏元素', element, '成功')
                validate = True
        return validate

    #获取一个元素的name属性
    def attribute_name(self, how, element, same_thing='none'):
        global validate
        global result
        event = self.wait_element(how, element)
        result = event.get_attribute('name')
        if same_thing == 'none':
            pass
        else:
            if same_thing == result:
                result = True
            else:
                result = False
        return result

    #翻页随机点击表单中的同一种元素(可指定具有一定特点元素的)
    def random_click(self, how1, element1, type='click', how2=0, element2=0):
        global event
        global result
        event = self.elements(how1, element1)
        #获取屏幕分辨率
        size = self.driver.get_window_size()
        width = size['width']
        height = size['height']
        size = event[0].size
        if size["height"] < 200:
            v_y = 200
        else:
            v_y = size["height"]
        #随机翻页并且随机选取元素
        time_no = 0
        while True:
            #翻页
            if len(event) > 1:
                for i in range(5):
                    self.driver.swipe(width * 500 / 1080, height * 1200 / 1766,
                                      width * 500 / 1080,
                                      height * (1200 - v_y) / 1766)
                if type == 'click':
                    time.sleep(3)
                    event[random.choice(range(len(event)))].click()
                else:
                    time.sleep(3)
                    TouchAction(self.driver).long_press(event[random.choice(
                        range(len(event)))]).wait(1).perform()
                result = True
                try:
                    if how2 == 'id':
                        event_check = self.driver.find_element_by_id(element2)
                    elif how2 == 'name':
                        event_check = self.driver.find_element_by_name(
                            element2)
                    elif how2 == 'class':
                        event_check = self.driver.find_element_by_class_name(
                            element2)
                    elif how2 == 'xpath':
                        event_check = self.driver.find_element_by_xpath(
                            element2)
                    result = True
                    break
                except:
                    time_no += 1
                    self.driver.back()
                    if time_no == 20:
                        result = False
            #不翻页
            else:
                if type == 'click':
                    time.sleep(1)
                    event[random.choice(range(len(event)))].click()
                else:
                    time.sleep(1)
                    TouchAction(self.driver).long_press(event[random.choice(
                        range(len(event)))]).wait(1).perform()
                result = True
                try:
                    if how2 == 'id':
                        event_check = self.driver.find_element_by_id(element2)
                    elif how2 == 'name':
                        event_check = self.driver.find_element_by_name(
                            element2)
                    elif how2 == 'class':
                        event_check = self.driver.find_element_by_class_name(
                            element2)
                    elif how2 == 'xpath':
                        event_check = self.driver.find_element_by_xpath(
                            element2)
                    result = True
                    break
                except:
                    time_no += 1
                    self.driver.back()
                    if time_no == 20:
                        result = False
        return result

    #随机点一个元素并获取其name属性
    def random_click_get_name(self, how, element):
        events = self.elements(how, element)
        no = random.choice(range(len(events)))
        time.sleep(1)
        name = events[no].get_attribute('name')
        events[no].click()
        return name

    def random_click_get_other_name(self, how1, element1, how2, element2):
        global events1
        global events2
        events1 = self.elements(how1, element2)
        events2 = self.elements(how2, element2)
        no = random.choice(range(len(events1)))
        time.sleep(1)
        name = events2[no].get_attribute('name')
        events1[no].click()
        return name

    #逐个元素点击根据一个元素的Name属性判断是不想要点击的元素
    def reach_click(self, how1, element1, how2, element2, decide_name, *args):
        global time_no
        global event_check
        global result
        events = self.elements(how1, element1)
        #获取屏幕分辨率
        size = self.driver.get_window_size()
        width = size['width']
        height = size['height']
        size = event[0].size
        v_y = size["height"]
        #按照元素高度滑动并且选取第二个元素
        time_no = 0
        while True:
            self.driver.swipe(width * 500 / 1080, height * 1200 / 1766,
                              width * 500 / 1080,
                              height * (1200 - v_y) / 1766)
            time.sleep(1)
            events[1].click()
            try:
                if how2 == 'id':
                    event_check = self.driver.find_element_by_id(element2)
                elif how2 == 'name':
                    event_check = self.driver.find_element_by_name(element2)
                elif how2 == 'class':
                    event_check = self.driver.find_element_by_class_name(
                        element2)
                elif how2 == 'xpath':
                    event_check = self.driver.find_element_by_xpath(element2)
                event_check_name = event_check.get_attribute('name')
                if decide_name == 'same':
                    print('same')
                    assert event_check_name == args[0]
                else:
                    print('not same')
                    for i in args:
                        assert event_check_name != i
                result = True
                break
            except:
                time_no += 1
                self.driver.back()
                if time_no == 10:
                    result = False
                    break
        return result

    #滑动页面到下一个页面,查看元素变化
    def swipe_page_left_right(self,
                              how,
                              element,
                              direction='left',
                              type='different'):
        global validate
        global result
        global event
        global time_no
        try:
            if how == 'id':
                event = self.driver.find_element_by_id(element)
            elif how == 'name':
                event = self.driver.find_element_by_name(element)
            elif how == 'class':
                event = self.driver.find_element_by_class_name(element)
            elif how == 'xpath':
                event = self.driver.find_element_by_xpath(element)
        except:
            #如果找不到元素进行截图,截图是按照当时时间来命名
            #判断如果没有指定失败图片且,同文件夹的名字为Fail_picture的文件夹新建一个
            try:
                os._exists(r'./Fail_picture') == False
                os.mkdir(r'./Fail_picture')
            except:
                pass
            #设置时间格式
            ISOTIMEFORMAT = '%Y%m%d_%X'
            localtime = str(time.strftime(ISOTIMEFORMAT,
                                          time.localtime())).replace(':', '')
            print('未找到想要获取的元素页面截图为:', localtime)
            #以时间来命名截屏
            self.driver.get_screenshot_as_file('./Fail_picture/' + localtime +
                                               '.png')
            result = False
        #获取屏幕分辨率
        size = self.driver.get_window_size()
        width = size['width']
        height = size['height']
        #滑动前判定元素截图
        self.Extend.get_screenshot_by_element(event).write_to_file(
            './Temp', 'Swipe_before')
        if direction == 'left':
            self.driver.swipe(width * 1050 / 1080, height * 500 / 1766,
                              width * 50 / 1080, height * 500 / 1766)
        else:
            self.driver.swipe(width * 50 / 1080, height * 500 / 1766,
                              width * 1050 / 1080, height * 500 / 1766)
        load = self.Extend.load_image('./Temp/Swipe_before.png')
        self.Extend.get_screenshot_by_element(event).write_to_file(
            './Temp', 'Swipe_after')
        result = self.Extend.get_screenshot_by_element(event).same_as(load, 0)
        if type == 'different':
            if result == False:
                return True
            else:
                return False
        else:
            return result

    #滑动后元素是否隐藏
    def swipe_existence(self, how, element):
        global validate
        global result
        global event
        global time_no
        event = self.wait_element(how, element)
        #获取屏幕分辨率
        size = self.driver.get_window_size()
        width = size['width']
        height = size['height']
        self.Extend.get_screenshot_by_element(event).write_to_file(
            './Temp', 'Swipe_existence')
        #获取屏幕分辨率
        self.driver.swipe(width * 500 / 1080, height * 500 / 1766,
                          width * 500 / 1080, height * 1000 / 1766)
        load = self.Extend.load_image('./Temp/Swipe_existence.png')
        try:
            result = self.Extend.get_screenshot_by_element(event).same_as(
                load, 0)
        except:
            result = False
        if result == False:
            result = True
        else:
            result = False
        return result

    #结果为真错误截图
    def check_assertTrue(self, exper, msg):
        if exper != True:
            try:
                os._exists(r'./Fail_picture') == False
                os.mkdir(r'./Fail_picture')
            except:
                pass
            #设置时间格式
            ISOTIMEFORMAT = '%Y%m%d_%X'
            localtime = str(time.strftime(ISOTIMEFORMAT,
                                          time.localtime())).replace(':', '')
            print('结果错误截图为:', localtime)
            #以时间来命名截屏
            self.driver.get_screenshot_as_file('./Fail_picture/' + localtime +
                                               '.png')
        self.tester.assertTrue(exper, msg)

    #结果为假错误截图
    def check_assertFalse(self, exper, msg):
        if exper != False:
            try:
                os._exists(r'./Fail_picture') == False
                os.mkdir(r'./Fail_picture')
            except:
                pass
            #设置时间格式
            ISOTIMEFORMAT = '%Y%m%d_%X'
            localtime = str(time.strftime(ISOTIMEFORMAT,
                                          time.localtime())).replace(':', '')
            print('结果错误截图为:', localtime)
            #以时间来命名截屏
            self.driver.get_screenshot_as_file('./Fail_picture/' + localtime +
                                               '.png')
        self.tester.assertFalse(exper, msg)

    #分享图片
    def share_picture_QQ(self):
        #单击直接发送按钮
        time.sleep(3)
        self.driver.find_element_by_id('com.bugua.fight:id/btn_send').click()
        #self.driver.find_element_by_name('QQ好友').click()
        time.sleep(2)
        #发送到QQ
        self.driver.find_element_by_name('QQ').click()
        time.sleep(2)
        self.driver.find_element_by_name('狗中极品').click()
        #点击发送
        time.sleep(2)
        self.driver.find_element_by_id(
            'com.tencent.mobileqq:id/dialogRightBtn').click()
        time.sleep(5)
        try:
            self.driver.find_element_by_name('返回斗图神器').click()
        except:
            self.driver.find_element_by_name('返回斗图神器_测试版').click()

    def share_picture_kongjian(self):
        #单击直接发送按钮
        time.sleep(3)
        self.driver.find_element_by_id('com.bugua.fight:id/btn_send').click()
        time.sleep(2)
        #发送到QQ空间
        self.driver.find_element_by_name('QQ空间').click()
        time.sleep(2)
        #发送到QQ空间
        self.driver.find_element_by_name('QQ空间').click()
        #点击发送
        time.sleep(2)
        self.driver.find_element_by_id(
            'com.tencent.mobileqq:id/dialogRightBtn').click()
        #点击返回斗图神器
        time.sleep(5)
        try:
            self.driver.find_element_by_name('返回斗图神器').click()
        except:
            self.driver.find_element_by_name('返回斗图神器_测试版').click()

    def share_picture_weixin(self):
        #单击直接发送按钮
        self.driver.find_element_by_id('com.bugua.fight:id/btn_send').click()
        time.sleep(2)
        # #临时没有微信号办法
        # self.driver.find_element_by_name('登录微信')
        #发送到微信
        self.driver.find_element_by_name('微信').click()
        time.sleep(2)
        #发送给管昭
        self.driver.find_element_by_name('管昭').click()
        time.sleep(2)
        self.driver.find_element_by_name('分享').click()
        time.sleep(1)
        self.driver.find_element_by_id('com.tencent.mm:id/a7m').click()

    def share_picture_pengyouquan(self):
        #单击直接发送按钮
        self.driver.find_element_by_id('com.bugua.fight:id/btn_send').click()
        time.sleep(2)
        # #临时没有微信号办法
        # self.driver.find_element_by_name('登录微信')
        #发送到朋友圈
        self.driver.find_element_by_name('朋友圈').click()
        #点击发送
        time.sleep(2)
        self.driver.find_element_by_name('发送').click()

    def share_picture_renren(self):
        #单击直接发送按钮
        self.driver.find_element_by_id('com.bugua.fight:id/btn_send').click()
        #发送到人人
        time.sleep(2)
        self.driver.find_element_by_name('人人').click()

    def share_picture_momo(self):
        #单击直接发送按钮
        self.driver.find_element_by_id('com.bugua.fight:id/btn_send').click()
        time.sleep(2)
        #发送到陌陌
        self.driver.find_element_by_name('陌陌').click()
        time.sleep(2)
        self.driver.find_element_by_id(
            'com.immomo.momo:id/signeditor_tv_text').send_keys('bugua')
        try:
            os._exists(r'./result') == False
            os.mkdir(r'./result')
        except:
            pass
        #设置时间格式
        ISOTIMEFORMAT = '%Y%m%d_%X'
        localtime = str(time.strftime(ISOTIMEFORMAT,
                                      time.localtime())).replace(':', '')
        print('结果错误截图为:', localtime)
        #以时间来命名截屏
        self.driver.get_screenshot_as_file('./result/momo' + localtime +
                                           '.png')
        self.driver.back()
        self.driver.find_element_by_name('确认').click()

    def share_package_QQ(self):
        #H5分享
        try:
            self.driver.find_element_by_id(
                'com.bugua.fight:id/btn_share').click()
        except:
            self.driver.find_element_by_name('分享表情包').click()
        time.sleep(2)
        #发送到QQ
        self.driver.find_element_by_name('QQ').click()
        time.sleep(2)
        #发送给狗中极品
        self.driver.find_element_by_name('狗中极品').click()
        time.sleep(2)
        self.driver.find_element_by_id(
            'com.tencent.mobileqq:id/dialogRightBtn').click()
        time.sleep(2)
        self.driver.find_element_by_id(
            'com.tencent.mobileqq:id/dialogLeftBtn').click()

    def share_package_kongjian(self):
        #H5分享
        try:
            self.driver.find_element_by_id(
                'com.bugua.fight:id/btn_share').click()
        except:
            self.driver.find_element_by_name('分享表情包').click()
        time.sleep(2)
        #发送到QQ空间
        self.driver.find_element_by_name('QQ空间').click()
        time.sleep(2)
        #选择QQ空间
        self.driver.find_element_by_name('QQ空间').click()
        time.sleep(2)
        #H5分享
        self.driver.find_element_by_id(
            'com.tencent.mobileqq:id/ivTitleBtnRightText').click()

    def share_package_weixin(self):
        #H5分享
        try:
            self.driver.find_element_by_id(
                'com.bugua.fight:id/btn_share').click()
        except:
            self.driver.find_element_by_name('分享表情包').click()
        time.sleep(2)
        # #临时没有微信号办法
        # self.driver.find_element_by_name('登录微信')
        #发送到微信
        self.driver.find_element_by_name('微信').click()
        time.sleep(2)
        #发送给管昭
        self.driver.find_element_by_name('管昭').click()
        time.sleep(2)
        #点击分享
        self.driver.find_element_by_name('分享').click()
        time.sleep(2)
        #返回斗图神器
        self.driver.find_element_by_id('com.tencent.mm:id/a7m').click()

    def share_package_pengyouquan(self):
        #H5分享
        try:
            self.driver.find_element_by_id(
                'com.bugua.fight:id/btn_share').click()
        except:
            self.driver.find_element_by_name('分享表情包').click()
        time.sleep(2)
        # #临时没有微信号办法
        # self.driver.find_element_by_name('登录微信')
        #发送到朋友圈
        self.driver.find_element_by_name('朋友圈').click()
        time.sleep(2)
        #点击发送
        self.driver.find_element_by_id('com.tencent.mm:id/eg').click()

    def share_package_renren(self):
        #H5分享
        try:
            self.driver.find_element_by_id(
                'com.bugua.fight:id/btn_share').click()
        except:
            self.driver.find_element_by_name('分享表情包').click()
        time.sleep(2)
        #发送到人人
        self.driver.find_element_by_name('人人').click()

    #获取当前元素与指定元素进行图片对比
    def cintrast_element_picture(self, how, element, picture):
        #元素检查和截图存放位置
        global validate
        global result
        global event
        try:
            if how == 'id':
                event = self.driver.find_element_by_id(element)
            elif how == 'name':
                event = self.driver.find_element_by_name(element)
            elif how == 'class':
                event = self.driver.find_element_by_class_name(element)
            elif how == 'xpath':
                event = self.driver.find_element_by_xpath(element)
            elif how == 'classes':
                element = element.split('[')
                event = self.driver.find_elements_by_class_name(element[0])
                event = event[int(element[1].split(']')[0])]
            elif how == 'ides':
                element1 = element.split('[')
                event = self.driver.find_elements_by_id(element[0])
                event = event[int(element[1].split(']')[0])]
            #检查是否有Temp文件夹没有就新建一个
            try:
                os._exists(r'./Temp') == False
                os.mkdir(r'./Temp')
            except:
                pass
            #截取元素点击前的图片
            self.Extend.get_screenshot_by_element(event).write_to_file(
                './Temp', 'click_before')
        except:
            #如果找不到元素进行截图,截图是按照当时时间来命名
            #判断如果没有指定失败图片且,同文件夹的名字为Fail_picture的文件夹新建一个
            try:
                os._exists(r'./Fail_picture') == False
                os.mkdir(r'./Fail_picture')
            except:
                pass
            #设置时间格式
            ISOTIMEFORMAT = '%Y%m%d_%X'
            localtime = str(time.strftime(ISOTIMEFORMAT,
                                          time.localtime())).replace(':', '')
            print('未找到要点击的元素页面截图为:', localtime)
            #以时间来命名截屏
            self.driver.get_screenshot_as_file('./Fail_picture/' + localtime +
                                               '.png')
            #assert event, '没有找到想要获取的元素'
            result = False
        load = self.Extend.load_image(picture)
        result = self.Extend.get_screenshot_by_element(event).same_as(load, 0)
        return result
class Imtest(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['deviceName'] = '3a11d697'
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '5.1.1'
        #desired_caps['unicodeKeyboard'] = "true"#使用 Unicode 输入法。默认值false
        #desired_caps['resetKeyboard'] = "true"#在设定了 unicodeKeyboard 关键字的 Unicode 测试结束后,重置输入法到原有状态。如果单独使用,将会被忽略。默认值 false
        desired_caps['appPackage'] = 'com.yuntongxun.ecdemo'
        desired_caps[
            'appActivity'] = 'com.yuntongxun.ecdemo.ui.LauncherActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub',
                                       desired_caps)
        self.verificationErrors = []
        self.driver.implicitly_wait(30)
        self.extend = Appium_Extend(self.driver)

    def test_get_screen_by_element(self):
        element = self.driver.find_element_by_id("chatting_content_iv")
        self.extend.get_screenshot_by_element(element).write_to_file(
            "f:\\screen", "image2")
        assert_true(os.path.isfile("f:\\screen\\image2.jpg"))

    def test_same_as(self):
        element = self.driver.find_element_by_id("chatting_content_iv")

        load = self.extend.load_image("f:\\screen\\image2.jpg")
        #要求百分百相似
        result = self.extend.get_screenshot_by_element(element).same_as(
            load, 0)
        assert_true(result)

    def test_send_readrurn(self):
        '''发送阅后即焚'''
        login.test_login(self, phoneid="13311267857")
        time.sleep(5)
        swip.swipLeft(self, 500)  #左划
        time.sleep(2)
        self.driver.find_element_by_id(
            "com.yuntongxun.ecdemo:id/card_item_tv").click()
        self.driver.find_element_by_id("content").click()
        self.driver.find_element_by_id("content").send_keys("13366778604")
        self.driver.find_element_by_id("text_right").click()
        #发送阅后即焚图片
        self.driver.find_element_by_id("chatting_attach_btn").click()
        self.driver.find_element_by_name(u"阅后即焚").click()
        self.driver.find_element_by_name(u"拍照").click()
        time.sleep(2)
        self.driver.find_element_by_id(
            "com.lenovo.scg:id/shutter_button").click()
        time.sleep(2)
        self.driver.find_element_by_id("com.lenovo.scg:id/btn_done").click()
        time.sleep(2)
        self.driver.find_element_by_id("text_right").click()

        self.driver.press_keycode('4')  #点击返回键
        #self.driver.find_element_by_id("chatting_content_itv").click()
        time.sleep(2)
        logout.test_logout(self)  #退出登录
        login.test_login(self, phoneid="13366778604")  #使用账号receive登录

        time.sleep(2)
        self.driver.find_element_by_name("13311267857").click()
        self.driver.find_element_by_id("chatting_content_iv").click()
        time.sleep(2)
        self.driver.press_keycode('4')  #点击返回键
        #获取点击后的图片
        self.test_get_screen_by_element()
        #对比焚毁的图片
        self.test_same_as()
        time.sleep(2)
        print u"接收图片成功"
        #发送阅后即焚图片

        x1 = self.driver.find_element_by_id(
            "chatting_content_iv").location.get('x')
        y1 = self.driver.find_element_by_id(
            "chatting_content_iv").location.get('y')
        print x1, y1
        x1 = int(x1) + 400
        y1 = int(y1) + 100
        print x1, y1

        self.driver.tap([(x1, y1)], 5000)
        self.driver.find_element_by_name(u"删除").click()
        self.driver.find_element_by_id("dilaog_button3").click()  #确认删除

        self.driver.press_keycode('4')  #点击返回键
        logout.test_logout(self)  #退出登录

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
class Imtest(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['deviceName'] = '3a11d697'  # 3a11d697 :红米note3
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '5.1.1'
        desired_caps[
            'appPackage'] = 'com.yuntongxun.eckuailiao'  #com.yuntongxun.eckuailiao
        desired_caps[
            'appActivity'] = 'com.yuntongxun.ecdemo.ui.account.SplashActivity'  #com.yuntongxun.ecdemo.ui.phonemodel.PhoneUI#com.yuntongxun.ecdemo.ui.account.LoginActivity
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub',
                                       desired_caps)
        self.verificationErrors = []
        self.driver.implicitly_wait(10)
        self.extend = Appium_Extend(self.driver)

    def test_get_screen_by_element(self):
        element = self.driver.find_element_by_id("video_icon")
        self.extend.get_screenshot_by_element(element).write_to_file(
            "f:\\screen", "image")
        assert_true(os.path.isfile("f:\\screen\\image.jpg"))

    def test_same_as(self):
        element = self.driver.find_element_by_id("video_icon")

        load = self.extend.load_image("f:\\screen\\image.jpg")
        #要求百分百相似
        result = self.extend.get_screenshot_by_element(element).same_as(
            load, 0)
        assert_true(result)

    def test_videocall(self):
        '''视频通话'''
        driver = self.driver
        #查找联系人
        login.test_login(self, phoneid="13311267857")  #使用账号13366778606登录
        #点击聊天
        self.driver.find_element_by_id(
            "com.yuntongxun.eckuailiao:id/btn_address_list").click()
        time.sleep(2)
        self.driver.find_element_by_id(
            "com.yuntongxun.eckuailiao:id/search").send_keys("13366778604")
        self.driver.find_element_by_id(
            "com.yuntongxun.eckuailiao:id/name_tv").click()
        self.driver.find_element_by_id(
            "com.yuntongxun.eckuailiao:id/phone_chat").click()
        self.driver.find_element_by_id("chatting_a ttach_btn").click()
        time.sleep(5)
        swip.swipLeft(self, 500)  #左划
        self.driver.find_element_by_name("17710556903").click()
        self.driver.find_element_by_id("entrance_chat").click()
        #self.driver.find_element_by_name("a1").click()
        time.sleep(5)
        wq = driver.find_element_by_id("chatting_attach_btn")
        assert_not_none(wq, u"未定位到加号按钮")
        wq.click()
        time.sleep(2)
        driver.tap([(400, 1660)], )  #点击

        print "Start : %s" % time.ctime()
        time.sleep(6)
        print "End : %s" % time.ctime()
        #图片对比
        self.test_get_screen_by_element()
        self.test_same_as()
        time.sleep(2)
        driver.find_element_by_id("video_botton_cancle").click()
        time.sleep(5)
        self.driver.press_keycode('4')  #点击返回键
        #logout.test_logout(self)#退出登录

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
Beispiel #8
0
class Follow_Test(unittest.TestCase):
    def setUp(self):
        print('Test start')
        #读取设备名字
        try:
            txt = open('./devices', 'r')
            phone = []
            for i in txt:
                phone.append(i)
            system1 = phone[0]
            device = phone[1]
            txt.close()
        except:
            system1 = '4.4.4'
            device = 'Android Emulator'
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '%s' % system1
        desired_caps['deviceName'] = '%s' % device
        desired_caps['appPackage'] = 'com.bugua.fight'
        desired_caps[
            'appActivity'] = 'com.yuelian.qqemotion.splash.SplashActivity'
        desired_caps['resetKeyboard'] = 'True'
        desired_caps['unicodeKeyboard'] = 'True'

        self.d = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        self.extend = Appium_Extend(self.d)
        self.ElementCheck = ElementCheck(self, self.d)
        time.sleep(5)

    def tearDown(self):
        print('Test end')
        self.d.quit()

    def Follow_user1(self):
        """从帖子中关注一个用户"""
        #点击大杂烩
        self.d.find_element_by_id('com.bugua.fight:id/all_area').click()
        # #向下拉屏幕隐藏帖子以外内容
        # size=self.d.get_window_size()
        # width=size['width']
        # height=size['height']
        # print(width,height)
        # self.d.swipe(width*200/1080, height*1500/1776, width*200/1080, height*720/1776)
        #翻页
        user_name = '丑到爆的同桌'
        while user_name == '丑到爆的同桌':
            self.ElementCheck.random_click('id',
                                           'com.bugua.fight:id/bbs_title')
            #在帖子中寻找用户头像
            self.ElementCheck.random_click('id', 'com.bugua.fight:id/avatar')
            #获取名字
            user_name = self.d.find_elements_by_class_name(
                'android.widget.TextView')
            user_name = user_name[1].get_attribute('name')
            print(user_name)
            if user_name == '丑到爆的同桌':
                continue
            #点击添加关注
            time.sleep(2)
            self.d.find_element_by_id('com.bugua.fight:id/btn_follow').click()
            time.sleep(5)
            user_data = self.d.find_element_by_xpath(
                '//android.support.v7.widget.RecyclerView/'
                'android.widget.LinearLayout/android.widget.LinearLayout[1]')
            self.extend.get_screenshot_by_element(user_data).write_to_file(
                '.\Temp', 'user_data')
            #进入我的关注页面
            self.d.back()
            self.d.back()
            self.d.find_element_by_id('com.bugua.fight:id/my_pic').click()
            self.d.find_element_by_name('关注').click()
            a1 = self.d.find_elements_by_name(user_name)
            self.d.find_element_by_name(user_name).click()
            self.assertEqual(len(a1), 1, msg='没有发现所关注的用户')
            #对比用户的个人资料,只对比了资料的部分(头像,用户名,签名)
            load = self.extend.load_image('.\Temp/user_data.png')
            user_data = self.d.find_element_by_xpath(
                '//android.support.v7.widget.RecyclerView/'
                'android.widget.LinearLayout/android.widget.LinearLayout[1]')
            self.extend.get_screenshot_by_element(user_data).write_to_file(
                '.\Temp', 'user_data2')
            result = self.extend.get_screenshot_by_element(
                self.d.find_element_by_xpath(
                    '//android.support.v7.widget.RecyclerView/android.widget.LinearLayout/android.widget.LinearLayout[1]'
                )).same_as(load, 0)
            self.ElementCheck.check_assertTrue(result, msg='用户资料显示有误')
            #取消关注
            self.d.back()
            self.d.find_element_by_id('com.bugua.fight:id/button').click()
            button1 = self.d.find_elements_by_name('关注')
            self.assertEqual(len(button1), 1, msg='取消关注Fail')
            #关注列表检查
            self.d.back()
            self.d.find_element_by_name('关注').click()
            button2 = self.d.find_elements_by_name(user_name)
            self.assertEqual(len(button2), 0, msg='关注列表自动刷新Fail')

    def Follow_package1(self):
        """从帖子中关注一个用户的表情包"""
        #点击大杂烩
        self.d.find_element_by_id('com.bugua.fight:id/all_area').click()
        while True:
            self.ElementCheck.random_click('id',
                                           'com.bugua.fight:id/bbs_title')
            #在帖子中寻找用户头像
            self.ElementCheck.random_click('id', 'com.bugua.fight:id/avatar')
            #获取名字
            user_name = self.d.find_elements_by_class_name(
                'android.widget.TextView')
            user_name = user_name[1].get_attribute('name')
            print(user_name)
            if user_name == '丑到爆的同桌':
                continue
            #单击表情包
            a = len(
                self.d.find_elements_by_xpath(
                    '//android.support.v7.widget.RecyclerView/\
                                      android.widget.FrameLayout/\
                                      android.widget.LinearLayout'))
            print(a)
            if a > 0:
                self.d.find_element_by_xpath(
                    '//android.support.v7.widget.RecyclerView/\
                                            android.widget.FrameLayout/\
                                            android.widget.LinearLayout[1]'
                ).click()
            else:
                self.d.back()
                self.d.back()
                user_name = '丑到爆的同桌'
                continue
            self.d.find_element_by_name(user_name).click()
            a2 = self.d.find_elements_by_name('个人资料')
            self.assertEqual(len(a2), 1, msg='进入用户资料失败')
            self.d.back()
            #点击收藏表情包
            self.ElementCheck.click_change('name', '关注表情包', 'hide')
            packagename = self.ElementCheck.attribute_name(
                'id', 'com.bugua.fight:id/folder_name')
            # time.sleep(5)
            # self.extend.get_screenshot_by_element(self.d.find_element_by_id('com.bugua.fight:id/recycler_view')).write_to_file('./Temp','packpage')
            #关注的表情包检查
            self.d.back()
            self.d.back()
            self.d.back()
            #点击我的
            self.d.find_element_by_id('com.bugua.fight:id/my_pic').click()
            #进入关注表情包
            self.d.find_element_by_name('关注表情包').click()
            result = self.ElementCheck.existence('name', user_name)
            self.ElementCheck.check_assertTrue(result, msg='未找到对应用户的表情包')
            #点击进入用户资料
            result = self.ElementCheck.click_jump('name', user_name, 'name',
                                                  '个人资料')
            self.ElementCheck.check_assertTrue(result, msg='未进入对应用的个人资料页面')
            self.d.back()
            #进入表情包
            self.d.find_element_by_xpath(
                '//android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]'
            ).click()
            # time.sleep(2)
            # load = self.extend.load_image('./Temp/packpage.png')
            # self.extend.get_screenshot_by_element(self.d.find_element_by_id('com.bugua.fight:id/recycler_view')).write_to_file('./Temp','packpage2')
            # result = self.extend.get_screenshot_by_element(self.d.find_element_by_id('com.bugua.fight:id/recycler_view')).same_as(load, 0)
            # self.ElementCheck.check_assertTrue(result, msg='收藏的表情包显示不一致')
            if self.ElementCheck.attribute_name(
                    'id', 'com.bugua.fight:id/folder_name') == packagename:
                result = True
            else:
                result = False
            self.assertTrue(result, msg='所收藏的表情包名称正确')
            time.sleep(1)
            #取消关注表情包
            test = self.d.find_elements_by_name('取消关注')
            print(len(test))
            self.d.find_element_by_name('取消关注').click()
            a4 = self.d.find_elements_by_name('关注表情包')
            self.assertEqual(len(a4), 1, msg='取消关注Fail')
            #返回关注列表页面检查
            self.d.back()
            a5 = self.d.find_elements_by_name(user_name)
            self.assertEqual(len(a5), 0, msg='取消关注查看页面Fail')
            break
Beispiel #9
0
class Imtest(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['deviceName'] = '3a11d697'
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '5.1.1'
        desired_caps['appPackage'] = 'com.yuntongxun.ecdemo'
        desired_caps[
            'appActivity'] = 'com.yuntongxun.ecdemo.ui.LauncherActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub',
                                       desired_caps)
        self.verificationErrors = []
        self.driver.implicitly_wait(30)
        self.extend = Appium_Extend(self.driver)

        #获得机器屏幕大小x,y
        x = self.driver.get_window_size()['width']
        y = self.driver.get_window_size()['height']
        l = [x, y]
        print l
        with open('F:\Appium\size\size.txt', 'w') as f:
            for i in range(len(l)):
                f.write(str(l[i]) + '\n')
                print l[i]
            f.close()

    def swipLeft(self, t):
        #l=[1080,1980]
        with open('F:\Appium\size\size.txt', 'r') as f:
            l = f.readlines()
            for i in range(len(l)):
                l[i] = int(l[i][:len(l[i]) - 1])
            print l
        x1 = int(l[0] * 0.75)
        y1 = int(l[1] * 0.5)
        x2 = int(l[0] * 0.05)
        print[x1, y1, x2, y1]
        self.driver.swipe(x1, y1, x2, y1, t)

    #屏幕向上滑动
    def swipeUp(self, t):
        with open('F:\Appium\size\size.txt', 'r') as f:
            l = f.readlines()
            for i in range(len(l)):
                l[i] = int(l[i][:len(l[i]) - 1])
        x1 = int(l[0] * 0.5)  #x坐标
        y1 = int(l[1] * 0.75)  #起始y坐标
        y2 = int(l[1] * 0.25)  #终点y坐标
        self.driver.swipe(x1, y1, x1, y2, t)

    def test_get_screen_by_element(self):
        element = self.driver.find_element_by_id("video_icon")
        self.extend.get_screenshot_by_element(element).write_to_file(
            "f:\\screen", "image")
        assert_true(os.path.isfile("f:\\screen\\image.jpg"))

    def test_same_as(self):
        element = self.driver.find_element_by_id("video_icon")

        load = self.extend.load_image("f:\\screen\\image.jpg")
        #要求百分百相似
        result = self.extend.get_screenshot_by_element(element).same_as(
            load, 0)
        assert_true(result)

    def test_videocall(self):
        '''视频通话'''
        driver = self.driver
        #查找联系人
        login.test_login(self, el="13311267857")  #使用账号13366778606登录
        #点击聊天
        ''' self.driver.find_element_by_name("a1").click()  
        #验证并删除上次发送的
        el=self.driver.find_element_by_id("tv_read_unread").get_attribute("text")
        assert_equal(el, u"已读", msg=u"状态验证失败")            
        print el+u" 阅读状态验证成功"
        el = self.driver.find_element_by_id("tv_read_unread")#状态
        action1 = TouchAction(self.driver)
        action1.long_press(el,duration=5000).perform()    
        self.driver.find_element_by_name(u"删除").click()
        self.driver.find_element_by_id("dilaog_button3").click()#确认删除
        self.driver.press_keycode('4')#点击返回键
        '''#点击聊天
        self.swipLeft(500)
        self.driver.find_element_by_name("17710556903").click()
        self.driver.find_element_by_id("entrance_chat").click()
        #self.driver.find_element_by_name("a1").click()
        time.sleep(5)
        wq = driver.find_element_by_id("chatting_attach_btn")
        assert_not_none(wq, u"未定位到加号按钮")
        wq.click()
        time.sleep(2)
        driver.tap([(400, 1660)], )  #点击

        print "Start : %s" % time.ctime()
        time.sleep(6)
        print "End : %s" % time.ctime()
        #图片对比
        self.test_get_screen_by_element()
        self.test_same_as()
        time.sleep(2)
        driver.find_element_by_id("video_botton_cancle").click()
        time.sleep(5)
        self.driver.press_keycode('4')  #点击返回键
        #logout.test_logout(self)#退出登录

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
Beispiel #10
0
class DraftingTest(unittest.TestCase):
    def setUp(self):
        print('Test start')
        #读取设备名字
        try:
            txt = open('./devices', 'r')
            phone = []
            for i in txt:
                phone.append(i)
            system1 = phone[0]
            device = phone[1]
            txt.close()
        except:
            system1 = '4.4.4'
            device = 'Android Emulator'
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '%s' % system1
        desired_caps['deviceName'] = '%s' % device
        desired_caps['appPackage'] = 'com.bugua.fight'
        desired_caps[
            'appActivity'] = 'com.yuelian.qqemotion.splash.SplashActivity'
        desired_caps['resetKeyboard'] = 'True'
        desired_caps['unicodeKeyboard'] = 'True'

        self.d = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        self.extnd = Appium_Extend(self.d)
        self.ElementCheck = ElementCheck(self, self.d)
        time.sleep(5)

    def tearDown(self):
        print('Test end')
        self.d.quit()

    #def Fight_souch_Test(self):

    def Fight_most_Test(self):
        """制图使用最多页面"""
        #点击制图
        result = self.ElementCheck.click_jump('id',
                                              'com.bugua.fight:id/zhitu_pic',
                                              'id',
                                              'com.bugua.fight:id/fight_tv')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击使用最多
        result = self.ElementCheck.click_jump('name', '使用最多', 'name', '使用最多')
        self.ElementCheck.check_assertTrue(result, msg='进入制图页面失败')

    def Fight_new_Test(self):
        """制图最近模板页面"""
        #点击制图
        result = self.ElementCheck.click_jump('id',
                                              'com.bugua.fight:id/zhitu_pic',
                                              'id',
                                              'com.bugua.fight:id/fight_tv')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击最新模板
        result = self.ElementCheck.click_jump('name', '最新模板', 'name', '最新模板')
        self.ElementCheck.check_assertTrue(result, msg='进入制图页面失败')

    def Fight_gif_Test(self):
        """制图动态模板页面"""
        #点击制图
        result = self.ElementCheck.click_jump('id',
                                              'com.bugua.fight:id/zhitu_pic',
                                              'id',
                                              'com.bugua.fight:id/fight_tv')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击动态模板
        result = self.ElementCheck.click_jump('name', '动态模板', 'name', '动态模板')
        self.ElementCheck.check_assertTrue(result, msg='进入制图页面失败')
        #点击最热
        #获取最热和最新两个tab切换按钮
        result = self.ElementCheck.click_change(
            'classes', 'android.support.v7.app.ActionBar$Tab[1]')
        self.ElementCheck.check_assertTrue(result, msg='最热点击后无反应')
        #点击最新
        #获取最热和最新两个tab切换按钮
        result = self.ElementCheck.click_change(
            'classes', 'android.support.v7.app.ActionBar$Tab[0]')
        self.ElementCheck.check_assertTrue(result, msg='最新点击后无反应')

    def Fight_popular_Test(self):
        """制图当前流行页面"""
        #点击制图
        result = self.ElementCheck.click_jump('id',
                                              'com.bugua.fight:id/zhitu_pic',
                                              'id',
                                              'com.bugua.fight:id/fight_tv')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击当前流行
        result = self.ElementCheck.click_jump('name', '当前流行')
        self.ElementCheck.check_assertTrue(result, msg='当前流行点击后无反应')

    def Classification_Test(self):
        """分类页面"""
        #点击制图
        result = self.ElementCheck.click_jump('id',
                                              'com.bugua.fight:id/zhitu_pic',
                                              'id',
                                              'com.bugua.fight:id/fight_tv')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击分类
        result = self.ElementCheck.click_jump(
            'id', 'com.bugua.fight:id/category_tv', 'id',
            'com.bugua.fight:id/module_classify_name')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #随机点击一个分类
        result = self.ElementCheck.random_click(
            'id', 'com.bugua.fight:id/module_classify_card_view', 'name', '全部')
        self.ElementCheck.check_assertTrue(result, msg='分类失败')
        #点击最新
        result = self.ElementCheck.click_change(
            'id', 'com.bugua.fight:id/new_order_detail')
        self.ElementCheck.check_assertTrue(result, msg='最新点击后无反应')
        #点击热门
        result = self.ElementCheck.click_change(
            'id', 'com.bugua.fight:id/hot_order_detail')
        self.ElementCheck.check_assertTrue(result, msg='点击热门失败')

    def Page_swipe_Test(self):
        """制图页面滑动查看"""
        #点击制图
        result = self.ElementCheck.click_jump('id',
                                              'com.bugua.fight:id/zhitu_pic',
                                              'id',
                                              'com.bugua.fight:id/fight_tv')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #向左滑动到装b区
        result = self.ElementCheck.swipe_page_left_right(
            'id', 'com.bugua.fight:id/show_off_tv', 'left')
        self.ElementCheck.check_assertTrue(result, msg='滑动页面失败')
        #向左滑动到分类
        result = self.ElementCheck.swipe_page_left_right(
            'id', 'com.bugua.fight:id/category_tv')
        self.ElementCheck.check_assertTrue(result, msg='滑动页面失败')
        #向左滑动到更多
        result = self.ElementCheck.swipe_page_left_right(
            'id', 'com.bugua.fight:id/more_tv')
        self.ElementCheck.check_assertTrue(result, msg='滑动页面失败')
        #更多向左滑动
        result = self.ElementCheck.swipe_page_left_right(
            'id', 'com.bugua.fight:id/more_tv', 'left', 'same')
        self.ElementCheck.check_assertTrue(result, msg='滑动页面失败')
        #向右滑动到分类
        result = self.ElementCheck.swipe_page_left_right(
            'id', 'com.bugua.fight:id/category_tv', 'right')
        self.ElementCheck.check_assertTrue(result, msg='滑动页面失败')
        #向右滑动到装b区
        result = self.ElementCheck.swipe_page_left_right(
            'id', 'com.bugua.fight:id/show_off_tv', 'right')
        self.ElementCheck.check_assertTrue(result, msg='滑动页面失败')
        #向右滑动到斗图区
        result = self.ElementCheck.swipe_page_left_right(
            'id', 'com.bugua.fight:id/fight_tv', 'right')
        self.ElementCheck.check_assertTrue(result, msg='滑动页面失败')
        #斗图区向右滑动
        result = self.ElementCheck.swipe_page_left_right(
            'id', 'com.bugua.fight:id/fight_tv', 'right', 'same')
        self.ElementCheck.check_assertTrue(result, msg='滑动页面失败')

    def MyProductionTest(self):
        """制图我的制作页面"""
        #点击制图
        result = self.ElementCheck.click_jump('id',
                                              'com.bugua.fight:id/zhitu_pic',
                                              'id',
                                              'com.bugua.fight:id/fight_tv')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击更多
        result = self.ElementCheck.click_change('id',
                                                'com.bugua.fight:id/more_tv')
        self.ElementCheck.check_assertTrue(result, msg='点击更多失败')
        #点击我的制作
        result = self.ElementCheck.click_jump(
            'id', 'com.bugua.fight:id/make_folder', 'name', '表情包详情')
        self.ElementCheck.check_assertTrue(result, msg='进入我的制作页面失败')

    def ChangePlanTest(self):
        """制图改图页面"""
        #点击制图
        result = self.ElementCheck.click_change(
            'id', 'com.bugua.fight:id/zhitu_pic')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击更多
        result = self.ElementCheck.click_change('id',
                                                'com.bugua.fight:id/more_tv')
        self.ElementCheck.check_assertTrue(result, msg='点击更多失败')
        #点击改图
        result = self.ElementCheck.click_jump('id',
                                              'com.bugua.fight:id/edit_pic',
                                              'name', '图片')
        self.ElementCheck.check_assertTrue(result, msg='进入改图选图页面失败')
        #随机选择图片
        self.ElementCheck.random_click('id', 'com.bugua.fight:id/pic_select')
        #对文字输入框内输入内容
        time.sleep(1)
        self.d.find_element_by_class_name('android.widget.EditText').clear()
        self.d.find_element_by_class_name('android.widget.EditText').send_keys(
            '我们是斗图神器')
        #修改背景颜色
        try:
            os._exists(r'./result') == False
            os.mkdir(r'./result')
        except:
            pass
        #点击文字背景色
        result = self.ElementCheck.click_jump(
            'id', 'com.bugua.fight:id/btn_change_bg_color', 'id',
            'com.bugua.fight:id/background_options')
        self.ElementCheck.check_assertTrue(result, msg='文字背景选择框失灵')
        self.d.get_screenshot_as_file('./result/background_options.jpg')
        #选择透明背景
        result = self.ElementCheck.click_jump(
            'id', 'com.bugua.fight:id/btn_bg_color_2', 'id',
            'com.bugua.fight:id/icon_bg_color_2')
        self.d.get_screenshot_as_file('./result/color2.jpg')
        self.ElementCheck.check_assertTrue(result, msg='透明背景失败')
        #选择白色背景
        result = self.ElementCheck.click_jump(
            'id', 'com.bugua.fight:id/btn_bg_color_1', 'id',
            'com.bugua.fight:id/icon_bg_color_1')
        self.d.get_screenshot_as_file('./result/color1.jpg')
        self.ElementCheck.check_assertTrue(result, msg='白色背景失败')
        #选择吸取背景
        result = self.ElementCheck.click_jump(
            'id', 'com.bugua.fight:id/btn_bg_color_3', 'id',
            'com.bugua.fight:id/btn_bg_color_3')
        self.d.get_screenshot_as_file('./result/color3.jpg')
        self.ElementCheck.check_assertTrue(result, msg='白色背景失败')
        #self.d.get_screenshot_as_file('./result/color3.jpg')
        #点击坐标位置为500,300的点
        self.d.tap([(500, 300)])
        self.d.get_screenshot_as_file('./result/color4.jpg')
        #点击字体颜色
        result = self.ElementCheck.click_jump(
            'id', 'com.bugua.fight:id/btn_change_txt_color', 'id',
            'com.bugua.fight:id/color_pick_area')
        self.ElementCheck.check_assertTrue(result, msg='字体颜色选择框失灵')
        #点击白色
        self.d.find_element_by_xpath(
            '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[1]'
        ).click()
        self.d.get_screenshot_as_file('./result/white.jpg')
        #描边
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        self.d.get_screenshot_as_file('./result/whiteStroke.jpg')
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        #点击黑色
        self.d.find_element_by_xpath(
            '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[2]'
        ).click()
        self.d.get_screenshot_as_file('./result/black.jpg')
        #描边
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        self.d.get_screenshot_as_file('./result/blackStroke.jpg')
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        #点击绿色
        self.d.find_element_by_xpath(
            '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[3]'
        ).click()
        self.d.get_screenshot_as_file('./result/green.jpg')
        #描边
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        self.d.get_screenshot_as_file('./result/greenStroke.jpg')
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        #点击橘黄
        self.d.find_element_by_xpath(
            '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[4]'
        ).click()
        self.d.get_screenshot_as_file('./result/orange.jpg')
        #描边
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        self.d.get_screenshot_as_file('./result/orangeStroke.jpg')
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        #点击红色
        self.d.find_element_by_xpath(
            '//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[5]'
        ).click()
        self.d.get_screenshot_as_file('./result/red.jpg')
        #描边
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        self.d.get_screenshot_as_file('./result/redStroke.jpg')
        self.d.find_element_by_id('com.bugua.fight:id/radio_stroke').click()
        #移动文字输入框
        size = self.d.get_window_size()
        width = size['width']
        height = size['height']
        print(width, height)
        text1 = self.d.find_elements_by_class_name("android.widget.EditText")
        print(len(text1))
        TouchAction(self.d).press(text1[1]).move_to(x=width * 76 / 768,
                                                    y=height * 150 /
                                                    1184).release().perform()
        time.sleep(5)
        self.d.find_element_by_xpath('//android.widget.EditText[1]').click()
        #关闭文字框
        #选取所有的android.widget.ImageView元素
        text = self.d.find_elements_by_xpath("//android.widget.ImageView")
        #点击第三个android.widget.ImageView元素对应为开始的文字框的关闭按钮
        text[2].click()
        self.d.get_screenshot_as_file('./result/closetext.jpg')
        #新建文字框
        self.d.find_element_by_id('com.bugua.fight:id/btn_new').click()
        self.d.get_screenshot_as_file('./result/newtext.jpg')
        #将新建的文字框输入内容
        self.d.find_element_by_xpath('//android.widget.EditText[1]').clear()
        self.d.find_element_by_xpath('//android.widget.EditText[1]').send_keys(
            '我们是斗图神器')
        #扩大文字框
        T = self.d.find_elements_by_xpath("//android.widget.ImageView")
        #print(len(T))
        TouchAction(self.d).long_press(T[3]).move_to(x=width * 900 / 1080,
                                                     y=height * 900 /
                                                     1920).release().perform()
        self.d.get_screenshot_as_file('./result/bigtext.jpg')
        #保存
        self.d.find_element_by_id('com.bugua.fight:id/btn_next').click()
        time.sleep(2)
        self.d.get_screenshot_as_file('./result/change_finsh.jpg')
        #点击完成按钮
        self.d.find_element_by_name('完成').click()

    def TemplateTest(self):
        """制图斗图制图"""
        #点击制图
        result = self.ElementCheck.click_change(
            'id', 'com.bugua.fight:id/zhitu_pic')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #在制图页面下选择一个模板
        self.ElementCheck.random_click(
            'xpath',
            '//android.support.v7.widget.RecyclerView/android.widget.FrameLayout'
        )
        #选择热门配文
        #第一次选择配文
        content = self.ElementCheck.random_click_get_name(
            'xpath', '//android.widget.ListView/android.widget.TextView')
        time.sleep(2)
        #检查所选择的配文显示的是否正确
        result = self.ElementCheck.attribute_name(
            'classes', 'android.widget.TextView[2]', content)
        self.ElementCheck.check_assertTrue(result, msg='显示错误')
        self.d.get_screenshot_as_file('./result/Template_text1.jpg')
        #下拉配文内容(至最低端)
        self.d.swipe(500 / 1080, 1800 / 1920, 500 / 1080, 1200 / 1920)
        content = self.ElementCheck.random_click_get_name(
            'xpath', '//android.widget.ListView/android.widget.TextView')
        result = self.ElementCheck.attribute_name(
            'classes', 'android.widget.TextView[2]', content)
        self.ElementCheck.check_assertTrue(result, msg='显示错误')
        #文字输入框
        self.d.find_element_by_id('com.bugua.fight:id/et_text').click()
        time.sleep(2)
        self.d.get_screenshot_as_file('./result/Template_edittext.jpg')
        #点击清空按钮
        self.d.find_element_by_id('com.bugua.fight:id/btn_clean').click()
        self.d.get_screenshot_as_file('./result/Template_clear.jpg')
        #输入内容(利用adb命令输入)
        os.system('adb shell input text bugua')
        #检查输入的配文显示的是否正确
        self.d.find_element_by_xpath('//android.widget.TextView[3]').get_attribute('name')\
        == 'bugua'
        self.d.get_screenshot_as_file('./result/Template_over.jpg')
        #保存
        self.d.find_element_by_id('com.bugua.fight:id/btn_next').click()
        time.sleep(2)
        self.d.get_screenshot_as_file('./result/Template_finsh.jpg')

    def zhuangbi_test(self):
        """制图装逼模板"""
        #点击制图
        result = self.ElementCheck.click_change(
            'id', 'com.bugua.fight:id/zhitu_pic')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击装b区
        result = self.ElementCheck.click_change(
            'id', 'com.bugua.fight:id/show_off_tv')
        self.ElementCheck.check_assertTrue(result, msg='进入装b区Fail')
        time.sleep(3)
        #点击一个分区
        a = {'1': '表白', '2': '恶搞', '3': '红包', '4': '证书', '5': '游戏', '6': '炫富'}
        no = str(random.choice(range(1, 5)))
        location = str('//android.widget.TextView[@text="%s"]/..' % a[no])
        print(location)
        self.ElementCheck.click('xpath', location)
        #选择模板
        time.sleep(2)
        self.ElementCheck.random_click('xpath', '//android.widget.ImageView')
        time.sleep(5)
        #选择模板
        # #随机点击今日新上中的图
        # temlpe = 'com.bugua.fight:id/template'+'%d'% (random.choice(range(0,2)))
        # self.d.find_element_by_id(temlpe).click()
        #下拉屏幕到低端
        time.sleep(3)
        size = self.d.get_window_size()
        w = size['width']
        h = size['height']
        self.d.swipe(w * 500 / 1080, h * 1800 / 1920, w * 500 / 1080,
                     h * 100 / 1920)
        #寻找图片添加按钮
        try:
            view = self.d.find_elements_by_id(
                'com.bugua.fight:id/pic_add_view')
            for i in range(len(view)):
                view[i].click()
                time.sleep(0.5)
                self.ElementCheck.random_click(
                    'id', 'com.android.documentsui:id/icon_thumb')
                time.sleep(0.5)
                self.d.find_element_by_id('com.bugua.fight:id/cut_btn').click()
        except:
            pass
        try:
            text = self.d.find_elements_by_id('com.bugua.fight:id/input_et')
            print(len(text))
            for i in range(len(text)):
                text[i].send_keys('bugua')
        except:
            pass
        time.sleep(0.5)
        self.ElementCheck.click_jump('id', 'com.bugua.fight:id/make', 'id',
                                     'com.bugua.fight:id/btn_finish')
        #结果文件夹
        try:
            os._exists(r'./result') == False
            os.mkdir(r'./result')
        except:
            pass
        self.extnd.get_screenshot_by_element(
            self.d.find_element_by_id(
                'com.bugua.fight:id/image_preview')).write_to_file(
                    './result', 'zhuangbi')

    def losts_pic_one_click1(self):
        """制图海量生成模板页面单击"""
        #点击制图
        result = self.ElementCheck.click_change(
            'id', 'com.bugua.fight:id/zhitu_pic')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击更多
        result = self.ElementCheck.click_change('id',
                                                'com.bugua.fight:id/more_tv')
        self.ElementCheck.check_assertTrue(result, msg='点击更多失败')
        #点击海量生成模板
        result = self.ElementCheck.click_jump(
            'id', 'com.bugua.fight:id/lots_pic_one_click', 'name', '一键生成')
        self.ElementCheck.check_assertTrue(result, msg='进入海量生成模板失败')
        #输入文字内容
        self.d.find_element_by_id('com.bugua.fight:id/et_content').send_keys(
            'bugua')
        #点击一键生成
        self.d.find_element_by_id('com.bugua.fight:id/one_key_btn').click()
        time.sleep(5)
        #截取生成内容图片
        try:
            os._exists(r'./Temp') == False
            os.mkdir(r'./Temp')
        except:
            pass
        picture = self.d.find_element_by_id('com.bugua.fight:id/recyclerView')
        self.extnd.get_screenshot_by_element(picture).write_to_file(
            './Temp', 'lost_pic')
        load = self.extnd.load_image('./Temp/lost_pic.png')
        #点击换一批
        self.d.find_element_by_name('换一批').click()
        time.sleep(5)
        #对比内容
        result = self.extnd.get_screenshot_by_element(picture).same_as(load, 0)
        self.assertFalse(result, msg='换一批失败')
        #选择图片分享出去
        self.ElementCheck.random_click('xpath',
                                       '//android.widget.ImageView/..')
        #点击收藏
        result = self.ElementCheck.click_change('id',
                                                'com.bugua.fight:id/btn_save')
        self.ElementCheck.check_assertTrue(result, msg='收藏按钮失败')
        #分享到微信
        self.ElementCheck.share_picture_weixin()

    def losts_pic_one_click2(self):
        """制图海量生成模板页面单击"""
        #点击制图
        result = self.ElementCheck.click_change(
            'id', 'com.bugua.fight:id/zhitu_pic')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击更多
        result = self.ElementCheck.click_change('id',
                                                'com.bugua.fight:id/more_tv')
        self.ElementCheck.check_assertTrue(result, msg='点击更多失败')
        #点击海量生成模板
        result = self.ElementCheck.click_jump(
            'id', 'com.bugua.fight:id/lots_pic_one_click', 'name', '一键生成')
        self.ElementCheck.check_assertTrue(result, msg='进入海量生成模板失败')
        #输入文字内容
        self.d.find_element_by_id('com.bugua.fight:id/et_content').send_keys(
            'bugua')
        #点击一键生成
        self.d.find_element_by_id('com.bugua.fight:id/one_key_btn').click()
        time.sleep(5)
        #截取生成内容图片
        try:
            os._exists(r'./Temp') == False
            os.mkdir(r'./Temp')
        except:
            pass
        picture = self.d.find_element_by_id('com.bugua.fight:id/recyclerView')
        self.extnd.get_screenshot_by_element(picture).write_to_file(
            './Temp', 'lost_pic')
        load = self.extnd.load_image('./Temp/lost_pic.png')
        #点击换一批
        self.d.find_element_by_name('换一批').click()
        time.sleep(5)
        #对比内容
        result = self.extnd.get_screenshot_by_element(picture).same_as(load, 0)
        self.assertFalse(result, msg='换一批失败')
        #选择图片分享出去
        self.ElementCheck.random_click('xpath',
                                       '//android.widget.ImageView/..',
                                       'long_pass')
        #点击收藏
        result = self.ElementCheck.click_change('id',
                                                'com.bugua.fight:id/btn_star')
        self.ElementCheck.check_assertTrue(result, msg='收藏按钮失败')
        #分享到微信
        self.ElementCheck.share_picture_weixin()

    def text_gif_text(self):
        """制图文字表情"""
        #点击制图
        result = self.ElementCheck.click_change(
            'id', 'com.bugua.fight:id/zhitu_pic')
        self.ElementCheck.check_assertTrue(result, msg='制图按钮失灵,进入制图页面失败')
        #点击更多
        result = self.ElementCheck.click_change('id',
                                                'com.bugua.fight:id/more_tv')
        self.ElementCheck.check_assertTrue(result, msg='点击更多失败')
        #点击海量生成模板
        result = self.ElementCheck.click_jump('id',
                                              'com.bugua.fight:id/text_gif',
                                              'name', '文字表情')
        self.ElementCheck.check_assertTrue(result, msg='进入海量生成模板失败')
        #移动文字框到左上角
        loction = self.d.find_element_by_id(
            'com.bugua.fight:id/img_container').location
        size = self.d.find_element_by_id(
            'com.bugua.fight:id/img_container').size
        #print(size)
        editText = self.d.find_element_by_xpath(
            '//*[@resource-id="com.bugua.fight:id/img_container"]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.EditText[1]'
        )
        TouchAction(self.d).press(editText).move_to(
            x=loction['x'] - editText.location['x'],
            y=loction['y'] - editText.location['y']).perform()
        time.sleep(1)
        self.d.get_screenshot_as_file(
            './result/text_gif_text_move_edittext.png')
        #将文字框扩大到最大
        button = self.d.find_element_by_xpath(
            '//*[@resource-id="com.bugua.fight:id/img_container"]/android.widget.FrameLayout/android.widget.ImageView'
        )
        TouchAction(self.d).long_press(button).move_to(
            x=(size['width'] - button.location['x']),
            y=(loction['y'] + size['height'] -
               button.location['y'])).release().perform()
        time.sleep(2)
        self.d.get_screenshot_as_file(
            './result/text_gif_text_edittext_max.png')
        #随机选择文案
        name = self.ElementCheck.random_click_get_name(
            'xpath',
            '//android.support.v7.widget.RecyclerView/android.widget.TextView')
        self.assertEqual(editText.get_attribute('name'), name, '选择文案失败')
        #点击字体
        self.ElementCheck.click_change('id', 'com.bugua.fight:id/font')
        #随机点击字体
        #self.extnd.get_screenshot_by_element(editText).write_to_file('./Temp','editText')
        self.ElementCheck.random_click(
            'xpath',
            '//*[@resource-id="com.bugua.fight:id/container"]/android.widget.LinearLayout/android.widget.FrameLayout'
        )
        self.d.get_screenshot_as_file(
            './result/text_gif_text_edittext_font.png')
        #点击颜色
        self.ElementCheck.click_change('id', 'com.bugua.fight:id/color')
        #随机选择颜色
        #self.extnd.get_screenshot_by_element(editText).write_to_file('./Temp','editText')
        self.ElementCheck.random_click('id', 'com.bugua.fight:id/image')
        self.d.get_screenshot_as_file(
            './result/text_gif_text_edittext_color.png')
        #点击对其
        self.ElementCheck.click_change('id', 'com.bugua.fight:id/align')
        #随机选择对齐
        self.extnd.get_screenshot_by_element(editText).write_to_file(
            './Temp', 'editText')
        self.ElementCheck.random_click('id', 'com.bugua.fight:id/image')
        self.d.get_screenshot_as_file(
            './result/text_gif_text_edittext_align.png')
        #点击保存
        self.ElementCheck.click_change('id',
                                       'com.bugua.fight:id/right_corner_btn',
                                       'hide')
        #发送到微信
        self.ElementCheck.click_change('id',
                                       'com.bugua.fight:id/share_to_wechat',
                                       'hide')
        time.sleep(3)
        #发送给管昭
        self.d.find_element_by_name('管昭').click()
        time.sleep(2)
        self.d.find_element_by_name('分享').click()
        time.sleep(1)
        self.d.find_element_by_id('com.tencent.mm:id/a7m').click()