Beispiel #1
0
 def get_driver(cls):
     from selenium import webdriver
     try:
         browser = FileUtil.get_ini("../conf/base.ini", "ui", "browser")
         url = FileUtil.get_ini("../conf/base.ini", "ui", "url")
         print(browser)
         if cls.driver is None:
             cls.driver = getattr(webdriver, browser)()
             cls.driver.maximize_window()
             cls.driver.get(url)
             cls.driver.implicitly_wait(5)
     except BaseException:
         cls.logger.error("driver生成失败请检查配置文件中的浏览器名字")
     return cls.driver
Beispiel #2
0
 def login(self):
     data = FileUtil.get_excel('..\\conf\\test_info.ini', 'login',
                               'login_info')
     print(data)
     for i in range(len(data)):
         Login(self.driver).do_login(data[i])
         a = self.driver.find_element_by_xpath(
             '//*[@id="navbar"]/ul[2]/li[1]/a').text
         if data[i]["expect"] == "login-sucess":
             print(data[i]["expect"])
             print(data[i]["username"])
             if data[i]["username"] in a:
                 print("成功")
                 print(data[i]["username"])
                 Login(self.driver).logout()
             elif a != "尚未登录":
                 print("失败")
                 Login(self.driver).ok()
                 time.sleep(1)
         else:
             if data[i]["username"] in a and a != "尚未登录":
                 print(data[i]["username"])
                 print(a)
                 print("失败")
                 Login(self.driver).logout()
             else:
                 print("成功")
                 print(data[i]["username"])
                 Login(self.driver).ok()
                 time.sleep(1)
Beispiel #3
0
    def run(self):

        co = Caradd()

        test_script_path = FileUtil.get_txt_line('../conf/sariptapi.conf')

        for script_path in test_script_path:
            scripts = FileUtil.get_txt_line(script_path)
            for step in scripts:
                temp = step.split(',')
                # 获取关键字
                keyword = temp[1]
                print(temp)

                if hasattr(co, keyword):
                    getattr(co, keyword)()
Beispiel #4
0
 def get_session(cls):
     import requests
     session = requests.session()
     c = session.get(
         url="http://192.168.186.159:8080/SharedParkingPlace/image")
     login_url = FileUtil.get_ini("../conf/base.ini", "api", "login_url")
     res = session.get(url=login_url)
     # print(res.text)
     return session
Beispiel #5
0
def get_driver():
    driver = None
    from selenium import webdriver
    browser = FileUtil.get_ini("../conf/base.ini","ui","browser")
    print(browser)
    if driver is None:
        driver = getattr(webdriver,browser)()
        driver.implicitly_wait(5)
        driver.maximize_window()
    return driver
Beispiel #6
0
    def run(self):
        # 获取关键字方法所在的类的对象
        co = Collection
        # 获取关键字配置文件内容,返回字典
        kw_map = FileUtil.get_json('../conf/intepret')
        # print(kw_map)
        test_script_path = FileUtil.get_txt_line('../conf/script.conf')

        for script_path in test_script_path:
            scripts = FileUtil.get_txt_line(script_path)
            for step in scripts:
                temp = step.split(',')
                # 获取关键字
                keyword = temp[0]
                print(temp)
                params = tuple(temp[1:])
                if hasattr(co, kw_map[keyword]):
                    # pass
                    fun = getattr(co, kw_map[keyword])
                    print(params)
                    fun(*params)
Beispiel #7
0
    def find_elment(cls, section, option):

        attr = 0
        try:
            element_attr = FileUtil.get_ini_list('..\\conf\\base.ini', section)

            for element in element_attr:
                if option in element.keys():
                    attr = eval(element[option])
            return cls.driver.find_element(getattr(By, attr[0]), attr[1])
        except:
            return None
Beispiel #8
0
    def start(self, path):

        suite = unittest.TestSuite()
        loader = unittest.TestLoader()
        test_class_info = FileUtil.get_txt(path)
        # print(test_class_info)
        tests = loader.loadTestsFr(Caradd)
        print(tests)
        suite.addTests(tests)

        with open('report.html', 'w') as file:
            runner = HTMLTestRunner(stream=file, verbosity=2)
            runner.run(suite)
Beispiel #9
0
 def find_image(cls, target):
     image_path = "../image"
     screen_path = os.path.join(image_path, 'screen.png')
     ImageGrab.grab().save(screen_path)
     # 读取大图对象
     screen = cv2.imread(screen_path)
     # 读取小图对象
     template = cv2.imread(os.path.join(image_path, target))
     # 进行模板匹配,参数包括大图对象、小图对象和匹配算法
     result = cv2.matchTemplate(screen, template, cv2.TM_CCOEFF_NORMED)
     # 获取匹配结果
     min, max, min_loc, max_loc = cv2.minMaxLoc(result)
     similarity = FileUtil.get_ini("../conf/base.ini", "ui", "similarity")
     if max < float(similarity):
         return -1, -1
     x = max_loc[0] + int(template.shape[1] / 2)
     y = max_loc[1] + int(template.shape[0] / 2)
     return x, y
Beispiel #10
0
    def input_account(self, username):

        uname_element = UiUtil.find_elment('login', 'uname')
        UiUtil.input(uname_element, username)

    def input_password(self, password):
        upass_element = UiUtil.find_elment('login', 'upass')
        UiUtil.input(upass_element, password)

    def input_verifycode(self, verifycode):
        vfcode_element = UiUtil.find_elment('login', 'vfcode')
        UiUtil.input(vfcode_element, verifycode)

    def click_login_button(self):
        login_button_element = UiUtil.find_elment('login', 'login_button')
        UiUtil.click(login_button_element)

    def do_login(self, login_data):
        self.input_account(login_data['username'])
        self.input_password(login_data['password'])
        self.input_verifycode(login_data['verifycode'])
        self.click_login_button()


if __name__ == '__main__':
    driver = UiUtil.get_driver()
    data=FileUtil.get_excel("../conf/woniu.json", 0)
    print(data[0])
    Login(driver).do_login(data[0])
Beispiel #11
0
 def test_4comments(self):
     test_info = FileUtil.get_excel_api('..\\conf\\test_info.ini', 'car',
                                        'comments')
     Api.assert_api(test_info)
Beispiel #12
0
 def test_3delete(self):
     test_info = FileUtil.get_excel_api('..\\conf\\test_info.ini', 'car',
                                        'delete')
     Api.assert_api(test_info)
Beispiel #13
0
 def test_2changeuser(self):
     test_info = FileUtil.get_excel_api('..\\conf\\test_info.ini', 'car',
                                        'changeuser')
     Api.assert_api(test_info)
Beispiel #14
0
 def test_1caradd(self):
     test_info = FileUtil.get_excel_api('..\\conf\\test_info.ini', 'car',
                                        'caradd')
     Api.assert_api(test_info)