Exemple #1
0
import unittest

from PO.po_page import B9_about_us_page
from public import GetPhoneInfo, Common, Log, CreatePng, ScreenAssert
from time import sleep

log = Log.Logger(logger='About_Us').getLog()


class About_Us(unittest.TestCase):
    '''《关于我们》未实现:邮箱跳转第三方,服务热线跳转拨号,免责声明内容'''
    @classmethod
    def setUpClass(cls):
        log.critical("--------------------关于我们测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driver()
        self.Page = B9_about_us_page.About_us(self.driver)
        self.base = Common.Action(self.driver)
        self.png = CreatePng.CreatePNG(self.driver)

    @ScreenAssert.decorator
    def test_about_001(self):
        '''验证关于我们页面LOGO显示,截图对比'''
        self.Page.go_about_us()
        self.png.CreateCustomSizeNowPNG('test_about_001', 270, 288, 558, 576)
        self.assertEqual(self.base.gerLocOld('test_about_001'),
                         self.base.getLocNow('test_about_001'))

    @ScreenAssert.decorator
    def test_about_002(self):
from PO.po_btn import A3_time_man_btn
from public import Common, Log
from time import sleep
import datetime
from selenium.webdriver.common.by import By

log = Log.Logger(logger='time_page').getLog()


class time_page(Common.Action):

    time_btn_loc = A3_time_man_btn.config['time_btn_loc']
    Guide_home_page_btn = (By.ID, 'com.gwchina.lssw.parent:id/iv_time_guide')
    Guide_confirm_page_btn = (By.ID, 'com.gwchina.lssw.parent:id/tv_confirm')
    more_btn = (By.ID, 'com.gwchina.lssw.parent:id/tv_more')
    save_btn = (By.ID, 'com.gwchina.lssw.parent:id/btn_action')
    save_negative_btn = (By.ID, 'com.gwchina.lssw.parent:id/btn_negative')
    save_positive_btn = (By.ID, 'com.gwchina.lssw.parent:id/btn_positive')
    back_btn = (By.ID, 'com.gwchina.lssw.parent:id/iv_back')

    def click_time_btn(self):
        self.is_display(self.homepage_child_head_btn[1])
        self.find_element(*self.time_btn_loc).click()

    def click_Guide_confirm(self):
        self.find_element(*self.Guide_confirm_page_btn).click()

    def click_more(self):
        self.find_element(*self.more_btn).click()

    def click_save(self):
Exemple #3
0
集成测试用例
发送测试报告邮件
自动关闭AppiumServer
'''
import unittest
import os, time
from time import sleep
from public import SendEmail
from testDAL import AppiumServer
from config import phoneGetConfigInfo
from public import HTMLTestRunner, DefNowPng, Log

now = time.strftime('%Y-%m-%d-%H_%M_%S', time.localtime(time.time()))
day = time.strftime('%Y-%m-%d', time.localtime(time.time()))

log = Log.Logger(logger='runAllTest').getLog()
absPath = os.path.dirname(os.path.abspath('.'))
casePath = absPath + '\\test_case'
report = absPath + "\\report\\report_html\\"


def Creatsuite():
    testUnit = unittest.TestSuite()
    discover = unittest.defaultTestLoader.discover(casePath,
                                                   pattern='*_test.py',
                                                   top_level_dir=None)
    for test_suite in discover:
        for caseName in test_suite:
            testUnit.addTest(caseName)
    return testUnit
Exemple #4
0
#encoding=utf-8
import pymysql
from public import Log
from time import sleep

log = Log.Logger(logger='SQLDataInfo').getLog()


def get_area_list():
    sleep(3)
    try:
        #charset='utf8' 解决中文乱码问题
        #创建连接
        conn = pymysql.connect('172.168.50.26',
                               'csall',
                               '111111',
                               'lssw',
                               charset='utf8')
        cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
        #获取 com_device_state 表里的锁屏状态  locdek = 1 锁屏,locdek = 0 解屏
        #id = 948807 天机MINI 03
        #id = 948688 天机MINI 05
        cursor.execute(
            "select value from com_param_device where name = 'rail_position' and bind_id = 1097127"
        )
        lock = cursor.fetchall()
        #关闭游标、关闭数据库连接
        cursor.close()
        conn.close()
        return lock
    except:
Exemple #5
0
from PO.po_page import A2_url_man_page
import unittest
from public import GetPhoneInfo,Common,CreatePng,Log,GetSQLData,ScreenAssert
from time import sleep

log = Log.Logger(logger='URL_Management').getLog()

class URL_Management(unittest.TestCase):
    '''《网址管理》'''
    @classmethod
    def setUpClass(cls):
        log.critical("--------------------网址管理测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driver()
        self.Page = A2_url_man_page.url_page(self.driver)
        self.base = Common.Action(self.driver)
        self.png = CreatePng.CreatePNG(self.driver)
        self.sql = GetSQLData

    '''
    以下网址管理等级测试用例
    '''
    @ScreenAssert.decorator
    def test_url_A001_level(self):
        '''进入网址管理功能'''
        self.Page.go_url_homepage()
        self.assertEqual(self.base.get_assert('id','com.gwchina.lssw.parent:id/tv_title').text,"网址管理")

    @ScreenAssert.decorator
    def test_url_A002_level(self):
import unittest
from public import Log, Common, GetPhoneInfo, CreatePng, ScreenAssert
from PO.po_page import Z1_Login_page
from time import sleep

log = Log.Logger(logger='LoginTest').getLog()


class LoginTest(unittest.TestCase):
    '''《登录功能》'''
    @classmethod
    def setUpClass(cls):
        log.critical("--------------------登录功能测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driverClear()
        self.Page = Z1_Login_page.LoginPage(self.driver)
        self.base = Common.Action(self.driver)
        self.createpng = CreatePng.CreatePNG(self.driver)

    @ScreenAssert.decorator
    def test_login_001(self):
        '''截图对比登录页面LOGO以及字样'''
        self.Page.click_video()
        self.Page.click_start()
        self.base.is_display(self.Page.username_loc[1])
        self.createpng.CreateCustomSizeNowPNG('test_login_001', 0, 72, 1080,
                                              700)
        old = self.base.gerLocOld('test_login_001')
        now = self.base.getLocNow('test_login_001')
        self.assertEqual(old, now)
Exemple #7
0
import requests
from public import Log

log = Log.Logger(logger='APIDataInfo').getLog()

url = 'http://ic.cs1.gwchina.cn/system/connect'


def get_token():
    try:
        host = 'http://ic.cs1.gwchina.cn'
        endpoint = '/system/connect'
        headers = {
            "oem_type": "LSSW",
            "key": "98243574",
            "lang": "chs",
            "serial_no": "sn-android-parent"
        }
        url = ''.join(host + endpoint)
        resp = requests.post(url=url, json=headers)
        text = resp.json()
        token_value = text['token']
        log.info("My_api -> get_token -> 获取token值 %s " % token_value)
        return token_value
    except:
        log.info("My_api -> get_token -> 获取token值失败 ")


class GetApi(object):
    host = 'http://ic.cs1.gwchina.cn'
    token = get_token()
import unittest
from time import sleep

from PO.po_page import B3_childdevice_page
from public import GetPhoneInfo, Common, Log, CreatePng, ScreenAssert

log = Log.Logger(logger='Child_device').getLog()


class Child_device(unittest.TestCase):
    '''《孩子设备》'''
    @classmethod
    def setUpClass(cls):
        log.critical("--------------------孩子设备测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driver()
        self.Page = B3_childdevice_page.child_device(self.driver)
        self.base = Common.Action(self.driver)
        self.png = CreatePng.CreatePNG(self.driver)

    @ScreenAssert.decorator
    def test_child_device_001(self):
        '''跳转孩子设备、返回用例'''
        self.Page.go_child_device()
        self.base.swipe_to_down(2, 4)
        try:
            self.assertIsNotNone(
                self.base.get_assert('id', self.Page.delete_btn_loc[1]))
        finally:
            self.Page.click_back_btn()
Exemple #9
0
from public import Log
from selenium import webdriver
from appium import webdriver
from config import phoneGetConfigInfo

log = Log.Logger(logger='Appium').getLog()
desired_caps = phoneGetConfigInfo.ReadConfig().readDesiredCapsData()
log.critical('desired_caps : (%s) ' % desired_caps)


class Appium(object):
    def __init__(self):
        self.desired_caps = phoneGetConfigInfo.ReadConfig(
        ).readDesiredCapsData()

    def driverClear(self):
        desired_caps = {
            'platformName': 'Android',
            'platformVersion': self.desired_caps['platformVersion'],
            'deviceName': self.desired_caps['deviceName'],
            'appPackage': self.desired_caps['appPackage'],
            # 'noReset' : 'True',  # 去掉,每次启动app都会清除数据
            'automationName': self.desired_caps['automationName'],
            'appActivity': self.desired_caps['appActivity'],
            'uuid': self.desired_caps['deviceName'],
        }
        self.driver = webdriver.Remote(self.desired_caps['remote'],
                                       desired_caps)
        self.driver.implicitly_wait(30)
        return self.driver
from PO.po_page import A6_area_man_page
import unittest
from public import Common, GetPhoneInfo, CreatePng, GetApiData, Log, ScreenAssert
from time import sleep

log = Log.Logger(logger='AreaTest').getLog()


class AreaTest(unittest.TestCase):
    '''《安全区域》'''
    @classmethod
    def setUpClass(cls):
        log.critical("--------------------安全区域测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driver()
        self.page = A6_area_man_page.AreaPage(self.driver)
        self.base = Common.Action(self.driver)
        self.png = CreatePng.CreatePNG(self.driver)
        self.api = GetApiData.GetApi()
        self.log = log

    @ScreenAssert.decorator
    def test_area_001(self):
        '''验证进入安全区域页面'''
        self.page.go_area_homepage()
        self.assertIsNotNone(
            self.base.get_assert('id', self.page.add_area_btn[1]))

    @ScreenAssert.decorator
    def test_area_002(self):
Exemple #11
0
import os,time,smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
from email import encoders
from email.mime.base import MIMEBase

from public import Log

log = Log.Logger(logger='SendEmail').getLog()

# 3.定义:发送邮件,发送最新测试报告html
def SendEmail(html_path,log_path):
    try:
        # 打开文件
        f = open(html_path, 'rb')
        # 读取文件内容
        mail_body = f.read()
        # 关闭文件
        f.close()

        # 发送邮箱服务器
        smtpserver = 'smtp.exmail.qq.com'
        # 发送邮箱用户名/密码
        user = '******'
        password = '******'
        # 发送邮箱
        sender = '*****@*****.**'
        # 多个接收邮箱,单个收件人的话,直接是receiver='*****@*****.**'
        receiver = ['*****@*****.**','*****@*****.**']
        # 发送邮件主题以及Html附件
import unittest
from PO.po_page import B8_feedback_page
from public import GetPhoneInfo, Common, Log, CreatePng, ScreenAssert

log = Log.Logger(logger='FeedBack').getLog()


class FeedBack(unittest.TestCase):
    '''《意见反馈》'''
    @classmethod
    def setUpClass(cls):
        log.critical("--------------------意见反馈测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driver()
        self.Page = B8_feedback_page.config(self.driver)
        self.base = Common.Action(self.driver)
        self.png = CreatePng.CreatePNG(self.driver)

    @ScreenAssert.decorator
    def test_feedback_001(self):
        '''意见反馈页面跳转'''
        self.Page.go_feedback()
        self.assertIsNotNone(
            self.base.get_assert('id', self.Page.submit_loc[1]))

    @ScreenAssert.decorator
    def test_feedback_002(self):
        '''意见反馈下半个页面截图对比默认值'''
        self.Page.go_feedback()
        self.png.CreateCustomSizeNowPNG('test_feedback_002', 36, 855, 1080,
Exemple #13
0
from PIL import Image
from public import Log
import os
''' 待添加逻辑 判断是xpath 、 id'''
''' 创建预期结果图片,首先截取元素所在的整体页面(存放 .\data\page ),在截图元素图片(存放 .\data\loc )'''
''' 用例对比,open .\data\loc 对应的元素 与 用例所截取的图片做对比 '''

PngDataPath = os.path.dirname(os.path.abspath('.')) + '\\data'
log = Log.Logger(logger='CreatePNG').getLog()


class CreatePNG(object):
    def __init__(self, driver):
        self.driver = driver

    def CreateNowPNG(self, v, png, loc):
        self.driver.get_screenshot_as_file(PngDataPath +
                                           '\\page\\%s_page.png' % png)
        log.info("截取当前页面图片保存至 .\data\page 目录下")
        if v == 'id':
            location = self.driver.find_element_by_id(loc).location
            size = self.driver.find_element_by_id(loc).size

            left = location['x']
            top = location['y']
            right = location['x'] + size['width']
            bottom = location['y'] + size['height']

            now = Image.open(PngDataPath + '\\page\\%s_page.png' % png)
            im = now.crop((left, top, right, bottom))
            im.save(PngDataPath + '\\loc_now\\%s_page.png' % png)
from PO.po_page import C1_account_page,Z1_Login_page
from public import GetPhoneInfo,Common,Log,CreatePng,ScreenAssert
import unittest

log = Log.Logger(logger='Account_Security').getLog()

class Account_Security(unittest.TestCase):
    '''《账号与安全》绘制图案密码锁未写'''
    @classmethod
    def setUpClass(cls):
        log.critical("--------------------账号与安全测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driver()
        self.Page = C1_account_page.AccountPage(self.driver)
        self.base = Common.Action(self.driver)
        self.png = CreatePng.CreatePNG(self.driver)

    @ScreenAssert.decorator
    def test_account_001(self):
        '''账号与安全页面跳转'''
        self.Page.click_setting()
        self.assertIsNotNone(self.base.get_assert('xpath', self.Page.account_loc[1]))

    @ScreenAssert.decorator
    def test_account_002(self):
        '''账号与安全页面默认值'''
        self.Page.click_setting()
        self.Page.click_account()
        self.base.is_display(self.Page.all_back_loc[1])
        self.png.CreateCustomSizeNowPNG('test_account_002',0,72,1080,1776)
Exemple #15
0
* Fix missing scroll bars in detail log (Podi).
"""

# TODO: color stderr
# TODO: simplify javascript using ,ore than 1 class in the class attribute?

import datetime
import io
import sys
import time
import unittest
from xml.sax import saxutils

from public import Log

log = Log.Logger(logger='HTMLTestRunner').getLog()


# ------------------------------------------------------------------------
# The redirectors below are used to capture output during testing. Output
# sent to sys.stdout and sys.stderr are automatically captured. However
# in some cases sys.stdout is already cached before HTMLTestRunner is
# invoked (e.g. calling logging.basicConfig). In order to capture those
# output, use the redirectors for the cached stream.
#
# e.g.
#   >>> logging.basicConfig(stream=HTMLTestRunner.stdout_redirector)
#   >>>

class OutputRedirector(object):
    """ Wrapper to redirect stdout or stderr """
Exemple #16
0
# coding: utf-8
import time, os
from functools import wraps
from public import Log
'''
断言装饰器,仅适用于在测试用例断言失败时截图保存至 \\report\\assert_png\\%s'" % day
当函数的参数不确定时,可以使用*args 和**kwargs,*args 没有key值,**kwargs有key值。
'''

logAssert = Log.Logger(logger='screenAssert').getLog()
logTestIDInfo = Log.Logger(logger='TestIDInfo').getLog()

abs_path = os.path.dirname(os.path.abspath('.'))


def decorator(func):
    @wraps(func)
    def getscreenShot(self, *args, **kwargs):
        try:
            logTestIDInfo.critical('Test case ID: %s ' % func.__name__)
            return func(self, *args, **kwargs)
        except Exception as e:
            now_time = time.strftime('%H-%M-%S', time.localtime(time.time()))
            day = time.strftime('%Y-%m-%d', time.localtime(time.time()))
            assert_path = abs_path + '\\report\\assert_png\\' + day + '\\'
            if os.path.exists(assert_path):
                png_name = os.path.join(assert_path + '%s_' % now_time +
                                        '%s.png' % func.__name__)
                self.driver.get_screenshot_as_file(png_name)
            else:
                os.mkdir(r'%s' % assert_path)
Exemple #17
0
# -*- coding: utf-8 -*-
from PO.po_page import B2_settings_page
import unittest
from public import GetPhoneInfo, Common, CreatePng, Log, GetSQLData, ScreenAssert
from time import sleep

log = Log.Logger(logger='SettingTest').getLog()


class SettingTest(unittest.TestCase):
    '''《通知设置和其他设置,SQL数据库对比数据》'''
    @classmethod
    def setUpClass(cls):
        log.critical("--------------------登录页面注册功能测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driver()
        self.page = B2_settings_page.SettingPage(self.driver)
        self.base = Common.Action(self.driver)
        self.png = CreatePng.CreatePNG(self.driver)

    @ScreenAssert.decorator
    def test_setting_001_notifications(self):
        '''验证通知设置页面默认显示,截图对比'''
        self.page.click_setting()
        self.page.click_notifications()
        self.png.CreateCustomSizeNowPNG('test_setting_001_notifications', 0,
                                        72, 1080, 1776)
        self.assertEqual(self.base.gerLocOld('test_setting_001_notifications'),
                         self.base.getLocNow('test_setting_001_notifications'))
Exemple #18
0
from time import sleep
from public import Common, Log
from PO.po_btn import A2_url_man_btn
from selenium.webdriver.common.by import By

log = Log.Logger(logger='url_page').getLog()


class url_page(Common.Action):

    url_btn_loc = (By.XPATH, '//android.widget.TextView[@text="网址管理"]'
                   )  #网址管理按钮
    back_btn_loc = (By.ID, 'com.gwchina.lssw.parent:id/iv_back')  #网址管理返回按钮
    save_btn_loc = (By.ID, 'com.gwchina.lssw.parent:id/btn_action'
                    )  #保存/删除按钮(右上角)

    def click_url_btn(self):
        self.find_element(*self.url_btn_loc).click()

    def click_back_btn(self):
        self.find_element(*self.back_btn_loc).click()

    def click_save_or_delete_btn(self):
        self.find_element(*self.save_btn_loc).click()

    rank_btn_loc = (By.XPATH, '//android.widget.TextView[@text="管理等级"]'
                    )  #管理等级按钮
    expand_btn_loc = (By.ID, 'com.gwchina.lssw.parent:id/iv_expand'
                      )  #收起/更多设置按钮(默认展开对应收起按钮)
    level_btn_loc = (By.ID, 'com.gwchina.lssw.parent:id/tv_hint'
                     )  #XX 模式下,不允许孩子上网的类型
import unittest
from public import GetPhoneInfo, Common,Log,ScreenAssert
from PO.po_page import Z2_sign_up_page
from time import sleep

log = Log.Logger(logger='SignUpTest').getLog()

class SignUpTest(unittest.TestCase):
    '''登录页面注册功能'''

    @classmethod
    def setUpClass(cls):
        log.critical("--------------------登录页面注册功能测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driverClear()
        self.Page = Z2_sign_up_page.LoginPage(self.driver)
        self.base = Common.Action(self.driver)

    @ScreenAssert.decorator
    def test_signup_001_phone(self):
        '''验证进入立即注册页面功能'''
        self.Page.go_register_page()
        self.assertEqual(self.base.get_assert('id', 'com.gwchina.lssw.parent:id/tv_title').text,"注册")

    @ScreenAssert.decorator
    def test_signup_002_phone(self):
        '''验证立即注册页面返回功能'''
        self.Page.go_register_page()
        self.Page.click_all_back_btn()
        self.assertIsNotNone(self.base.get_assert('id','com.gwchina.lssw.parent:id/ed_username'), 'error')
Exemple #20
0
from selenium.webdriver.support.wait import WebDriverWait
from time import sleep
from public import Log, SaveCreen
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from PIL import Image
import os

absPath = os.path.dirname(os.path.abspath('.'))
log = Log.Logger(logger='Common').getLog()


class Action():
    def __init__(self, driver):
        self.driver = driver

    def find_elementOld(self, *loc):
        # try:
        #     WebDriverWait(self.driver, 10, 0.5, ).until(lambda driver: driver.find_element(*loc).is_displayed())
        #     return self.driver.find_element(*loc)
        # except:
        #     SaveCreen.ScreenShot(self.driver).saveScreen()
        #     log.error(
        #         "‘find_element(*loc).is_displayed()’ The page was not found ‘%s’ element,Save the screen shot as the ‘.\\report\\report_html’ folder " %
        #         loc[1])

        try:
            WebDriverWait(self.driver, 20,
                          0.5).until(EC.visibility_of_element_located(loc))
            try:
                WebDriverWait(
import unittest
from time import sleep
from PO.po_page import A3_time_man_page
from public import Common, GetPhoneInfo, CreatePng, Log, ScreenAssert

log = Log.Logger(logger='TimeTest').getLog()


class TimeTest(unittest.TestCase):
    '''《时间管理》'''
    @classmethod
    def setUpClass(cls):
        log.critical("--------------------时间管理测试开始--------------------")

    def setUp(self):
        self.driver = GetPhoneInfo.Appium().driver()
        self.page = A3_time_man_page.time_page(self.driver)
        self.png = CreatePng.CreatePNG(self.driver)
        self.base = Common.Action(self.driver)

    @ScreenAssert.decorator
    def test_time_A001(self):
        '''首次进入时间管理验证引导页显示'''
        self.page.click_time_btn()
        self.base.is_display(self.page.Guide_confirm_page_btn[1])
        self.png.CreateCustomSizeNowPNG('test_time_001', 0, 490, 1080, 1350)
        self.assertEqual(self.base.gerLocOld('test_time_001'),
                         self.base.getLocNow('test_time_001'))

    @ScreenAssert.decorator
    def test_time_A002(self):