예제 #1
0
 def setUpClass(cls):
     global driver, countA
     #appium启动服务只运行一次
     if countA == 1:
         # 启动appium服务
         os.system('start startAppiumServer.bat')
     countA = countA + 1
     # 所有的test运行前运行一次
     desired_caps = {
         'platformName': 'Android',
         'platformVersion': '7.1.1',
         'deviceName': 'Android Emulator',
         'appPackage': 'hello.free.music.offline.trending.music.iplay',
         'appActivity':
         'hello.free.music.offline.trending.music.iplay.splash.SplashActivity',
         'unicodeKeyboard': 'True',  #使用unicode方式发送字符
         'resetKeyboard': 'True',  #隐藏键盘
         'noReset': 'True',  # 如果app存在,不再重新安装
         'app': PATH('./apps/HelloFreeMusic.apk')
     }
     try:
         cls.driver = webdriver.Remote('http://localhost:4723/wd/hub',
                                       desired_caps)
         myLog.logger().info('driver加载成功 %s', cls.driver)
     except Exception as e:
         myLog.logger().info('driver加载失败 %s', e)
예제 #2
0
 def setUpClass(cls):
     global driver, countA
     #appium启动服务只运行一次
     if countA == 1:
         # 启动appium服务
         os.system('start startAppiumServer.bat')
     countA = countA + 1
     # 所有的test运行前运行一次
     desired_caps = {
         'platformName': 'Android',
         'platformVersion': '9',
         'deviceName': '127.0.0.1:4723',
         'appPackage': 'net.reead.home',
         'appActivity': 'net.reead.home.login.view.activity.SplashActivity',
         'unicodeKeyboard': 'True',  #使用unicode方式发送字符
         'resetKeyboard': 'True',  #隐藏键盘
         'noReset': 'True',  # 如果app存在,不再重新安装
         'app': PATH('./apps/ReeadHome_v3.1.2_Huawei(2).apk')
     }
     try:
         cls.driver = webdriver.Remote('http://localhost:4723/wd/hub',
                                       desired_caps)
         myLog.logger().info('driver加载成功 %s', cls.driver)
     except Exception as e:
         myLog.logger().info('driver加载失败 %s', e)
         cls.driver.implicitly_wait(10)
예제 #3
0
def window_pop(driver, xpath, n):

    for i in range(n):
        try:
            em = WebDriverWait(driver, 1, 0.5).until(
                EC.presence_of_element_located(xpath))
            em.click()
            myLog.logger().info('定位成功 %s', em)
        except Exception as e:
            myLog.logger().error('定位播放pop权限框失败 %s', e)
예제 #4
0
def isElementExist(flag, driver, xpath):
    isExist = True
    if flag == 0:
        # noinspection PyBroadException
        try:
            driver.find_element_by_xpath(xpath).is_displayed()
        except Exception as e:
            myLog.logger().error("查找的元素不存在 %s %s", xpath, e)
            isExist = False
        return isExist
    elif flag == 1:
        # noinspection PyBroadException
        try:
            driver.find_element_by_id(xpath).is_displayed()
        except Exception as e:
            myLog.logger().error("查找的元素不存在 %s %s", xpath, e)
            isExist = False
        return isExist
    elif flag == 2:
        try:
            driver.find_elements_by_name(xpath).is_displayed()
        except Exception as e:
            myLog.logger().error("查找的元素不存在 %s %s", xpath, e)
            isExist = False
        return isExist
예제 #5
0
 def setUpClass(cls):
     print("setUpClass\n")
     global driver
     #所有的test运行前运行一次
     # noinspection PyUnreachableCode
     #获取浏览器配置信息
     browserType = int(myConfig.getDriver())
     #获取测试url
     testUrl = myConfig.getUrl()
     if browserType == 1:
         fp = webdriver.FirefoxProfile()
         # 设置下载方式, 0是桌面 1是我的下载 2是自定义
         fp.set_preference("browser.down.folderList", 2)
         # 自定义下载地址
         fp.set_preference("browser.download.dir", 'f:\\project')
         # 总是询问文件的保存位置,True代表不再询问
         fp.set_preference("browser.download.useDownloadDir", True)
         # 下载的时候是否显示下载管理器;默认true显示,false不显示
         fp.set_preference("browser.download.manager.showWhenStarting", False)
         # 无需确认下载的文件格式
         fp.set_preference("browser.helperApps.neverAsk.saveToDisk",
                           "application/octet-stream, application/vnd.ms-excel,"
                           " text/csv, application/zip,application/xml")
         try:
             cls.driver = webdriver.Firefox()
         except Exception as e:
             myLog.logger().error('浏览器firefox driver有误 %s', e)
     elif browserType == 2:
         try:
             #download.default_directory:设置下载路径
             #profile.default_content_settings.popups:设置为0,禁止弹出窗口
             options = webdriver.ChromeOptions()
             prefs = {'profile.default_content_settings.popups': 0, 'download.default_directory': 'f:\\project'}
             options.add_experimental_option('prefs', prefs)
             cls.driver = webdriver.Chrome(chrome_options=options)
         except Exception as e:
             myLog.logger().error('浏览器chrome driver有误 %s', e)
     cls.driver.get(testUrl)
     cls.driver.maximize_window()
예제 #6
0
 def test_Login(self):
     #设置用例名称
     self._testMethodDoc = self.case_Name
     myLog.logger().info('测试用例名称:' + self._testMethodDoc)
     myLog.logger().info('测试用例说明:' + self.reMark)
     # 点击手机号输入框
     login_Page.click_phone(self.driver)
     user_Namek = str(self.user_Name)
     user_NameP = user_Namek[0:11]
     myLog.logger().info('手机号: %s', user_NameP)
     #  输入手机号
     login_Page.search_input(self.driver, user_NameP)
     myLog.logger().info('短信: %s', self.user_VerCode)
     # 输入验证码
     login_Page.search_verifyinput(self.driver, self.user_VerCode)
     # 点击登陆
     login_Page.click_login(self.driver)
     # 提示正确验证码截图
     time.sleep(0.5)
     common.Screenshot1(self.driver)
예제 #7
0
    def test_Login(self):
        #设置用例名称
        self._testMethodDoc = self.case_Name
        myLog.logger().info('测试用例名称:' + self._testMethodDoc)
        myLog.logger().info('测试用例说明:' + self.reMark)

        # 点击手机号输入框
        login_Page.click_phone(self.driver)
        user_Namek = str(self.user_Name)
        user_NameP = user_Namek[0:12]
        myLog.logger().info('输入手机号  %s', user_NameP)
        # # 输入手机号
        login_Page.search_input(self.driver, user_NameP)
        # 点击登陆
        login_Page.click_login(self.driver)
        time.sleep(0.5)
        # 提示验证码后截图
        common.Screenshot1(self.driver)
예제 #8
0
 def test_Dowload(self):
     #设置用例名称
     self._testMethodDoc = self.case_Name
     myLog.logger().info('测试用例名称:' + self._testMethodDoc)
     myLog.logger().info('测试用例说明:' + self.reMark)
     time.sleep(2)
     #判断主界面是否加载到数据
     if home_Page.is_empty(self.driver):
         #数据加载失败的截屏
         common.Screenshot1(self.driver)
         home_Page.click_empty(self.driver)
         time.sleep(8)
     #点击首页的Search菜单
     home_Page.click_search(self.driver)
     #点击搜索界面的搜索框
     home_Page.click_searchbg(self.driver)
     #搜索界面的截屏
     common.Screenshot1(self.driver)
     #输入要搜索的内容
     myLog.logger().info('搜索内容 %s', self.search_data)
     home_Page.search_input(self.driver, self.search_data)
     #点击youtube搜索工具条
     home_Page.click_youtube(self.driver)
     time.sleep(3)
     #滑动屏幕进行,查找要点击的内容
     common.swipeUp1(self.driver, 1)
     #点击要播放的视频
     home_Page.click_video(self.driver)
     time.sleep(3)
     #等待视频播放完成
     time.sleep(home_Page.get_time(self.driver))
     common.Screenshot1(self.driver)
     home_Page.click_back(self.driver)
     home_Page.click_back(self.driver)
     home_Page.click_back(self.driver)
     home_Page.click_home(self.driver)
     #主界面是否有下载的截屏
     common.Screenshot1(self.driver)
     self.assertEqual(True, self.excepted)
예제 #9
0
    '''运行之前获取config.ini配置里面的result,0表示result文件夹下面的内容每次运行都保存下来,
      1表示只保存最后一次运行的结果'''
    result = myConfig.getResult()
    if result == 1:
        #截图文件的路径
        imPath = os.path.join(path, 'Mobile_Ui', 'result', 'image')
        #日志文件的路径
        logPath = os.path.join(path, 'Mobile_Ui', 'result', 'logs')
        #测试报告的路径
        reportPath = os.path.join(path, 'Mobile_Ui', 'result', 'report')
        common.delFile(imPath)
        common.delFile(logPath)
        common.delFile(reportPath)
    suite = runSet.set_suite()
    #获取report的存放路径
    filePath = myLog().getReportPath()
    fb = open(filePath, 'wb')
    runner = HTMLTestReport(stream=fb,
                            verbosity=2,
                            title='Music UI Test',
                            description='Music TestCase')
    runner.run(suite)
    fb.close()
    myLog.logger().info('测试用例个数 %s', suite.countTestCases())
    #测试邮件发送
    mail = runSet.send_Mail(filePath, 'Music UI Test')
    if mail:
        myLog.logger().info('邮件发送成功!')
    else:
        myLog.logger().info('邮件发送失败!')
예제 #10
0
    '''运行之前获取config.ini配置里面的result,0表示result文件夹下面的内容每次运行都保存下来,
      1表示只保存最后一次运行的结果'''
    result = myConfig.getResult()
    if result == 1:
        #截图文件的路径
        imPath = os.path.join(path, 'WebUi', 'result', 'image')
        #日志文件的路径
        logPath = os.path.join(path, 'WebUi', 'result', 'logs')
        #测试报告的路径
        reportPath = os.path.join(path, 'WebUi', 'result', 'report')
        common.delFile(imPath)
        common.delFile(logPath)
        common.delFile(reportPath)
    suite = runSet.set_suite()
    print('suite', suite)
    #获取report的存放路径
    filePath = myLog().getReportPath()
    fb = open(filePath, 'wb')
    runner = HTMLTestReportEN(stream=fb,
                              verbosity=2,
                              title='Music UI Test',
                              description='Music TestCase')
    runner.run(suite)
    fb.close()
    #测试邮件发送
    mail = runSet.send_Mail(filePath, 'Music Test')
    if mail:
        myLog.logger().info('邮件发送成功!')
    else:
        myLog.logger().info('邮件发送失败!')
예제 #11
0
    def test_Login(self):
        #设置用例名称
        self._testMethodDoc = self.case_Name
        myLog.logger().info('测试用例名称:' + self._testMethodDoc)
        myLog.logger().info('测试用例说明:' + self.reMark)
        #判断是否第一次登录,如果是走第一次登录的界面,否则走登录后的界面
        if login_Page.is_login(self.driver):

            #开始按钮
            login_Page.click_login(self.driver)
            time.sleep(2)
            #点击开始按钮后进行截屏
            common.Screenshot1(self.driver)
            #判定是否拉取到音乐类型的后台数据,如果拉取到就进行选择,否则直接点击下一步
            if login_Page.is_Type(self.driver):
                # 音乐类型选择
                login_Page.select_type(self.driver)
                #音乐类型保存
                login_Page.click_save(self.driver)
                time.sleep(5)
                #系统权限框
                home_Page.click_Allow(self.driver)
                time.sleep(3)
            else:
                login_Page.click_skip(self.driver)
                time.sleep(3)
                #系统权限框
                home_Page.click_Allow(self.driver)
                time.sleep(8)
            if home_Page.is_empty(self.driver):
                home_Page.click_empty(self.driver)
                time.sleep(5)
        #向上滑动,n:滑动次数
        common.swipeUp(self.driver, 1)
        #滑动首页后进行截屏
        common.Screenshot1(self.driver)
        #首页点击进入播放列表页
        time.sleep(2)
        home_Page.click_list(self.driver)
        #点击play播放按钮
        home_Page.click_paly(self.driver)
        #判断是否有系统权限弹窗
        if home_Page.sys_playPermiss(self.driver):

            #播放权限框
            home_Page.click_pop(self.driver)
            #播放系统权限界面的截屏
            common.Screenshot1(self.driver)
            #打开music的权限框
            home_Page.open_playPermiss(self.driver)
            # 点击手机返回键,返回程序播放界面
            home_Page.click_back(self.driver)
        # 点击手机返回键,返回程序主界面
        time.sleep(1)
        home_Page.click_back(self.driver)
        time.sleep(2)
        #返回主界面的截屏
        common.Screenshot1(self.driver)
        self.assertEqual(True, self.excepted)

        #正常登陆的测试用例
        '''if self._testMethodDoc == 'test_login1':
예제 #12
0
def setUserName(driver, userName):
    myLog.logger().info('use_namedriver: %s', driver)
    driver.find_element_by_name('email').send_keys(userName)