Exemple #1
0
class LoginPage():

    _account = By.CLASS_NAME, 'account-form-input'
    _pwd = By.CLASS_NAME, 'password'
    _login_btn = By.CLASS_NAME, 'account-form-field-submit'
    _link_book = By.CLASS_NAME, 'lnk-book'

    def __init__(self):
        logger.info("初始化LoginPage")
        self.driver = WDriver().get_driver()
        logger.info("selenum id:{}".format(id(self.driver)))
        # ConfigParser.read_config()
        # self.user_name = ConfigParser.get_config('username', 'user_name')
        # logger.info("账号:{}".format(self.user_name))
        # ConfigParser.config_dic = {}
        # self.pwd = ConfigParser.get_config('pwd', 'pwd')
        # logger.info("密码:{}".format(self.pwd))

    def login(self):
        self.driver.find_element(*self._account).clear()
        self.driver.find_element(*self._account).send_keys(user_name)
        self.driver.find_element(*self._pwd).clear()
        self.driver.find_element(*self._pwd).send_keys(pwd)
        self.driver.find_element(*self._login_btn).click()
        logger.info("点击登录")
Exemple #2
0
 def addFailure(self, test, err):
     self.failure_count += 1
     self.status = 1
     TestResult.addFailure(self, test, err)
     _, _exc_str = self.failures[-1]
     output = self.complete_output()
     self.result.append((1, test, output, _exc_str))
     # if not getattr(test, "driver",""):
     #     pass
     # else:
     #     try:
     #         driver = getattr(test, "driver")
     #         test.imgs.append(driver.get_screenshot_as_base64())
     #     except Exception as e:
     #         pass
     try:
         driver = WDriver().get_driver()
         my_log = init_logger()
         my_log.info("****addFailure****")
         fail_image = "<img src=\"data:image/png;base64,{}\"/>".format(
             driver.get_screenshot_as_base64())
         log = [str(err), fail_image]
         self.test_result_list.append(
             self.gen_case_info(str(test), "addFailure", log))
     except Exception as e:
         print(e)
     if self.verbosity > 1:
         sys.stderr.write('F  ')
         sys.stderr.write(str(test))
         sys.stderr.write('\n')
     else:
         sys.stderr.write('F')
 def wrapper(*args, **kw):
     # print('%s():' % (func.__name__))
     with allure.step('添加截图'):
         allure.attach('添加截图', WDriver().get_driver().get_screenshot_as_png(), type=AttachmentType.PNG)
     f = func(*args, **kw)
     with allure.step('添加截图'):
         allure.attach('添加截图', adb_screen_shot(), type=AttachmentType.PNG)
     return f
Exemple #4
0
class BasePage(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        logger.info("父类setUpClass初始化")

    def setUp(self):
        logger.info("父类初始化")
        self.driver = WDriver().init_driver()
        logger.info("selenum id:{}".format(id(self.driver)))
        self.driver.get("https://www.douban.com")

    def tearDown(self):
        logger.info("父类结束")
        self.driver.quit()

    @classmethod
    def tearDownClass(cls):
        logger.info("父类tearDownClass结束")
Exemple #5
0
class BookPage():

    _search_text = By.ID, 'inp-query'
    _inp_btn = By.CLASS_NAME, 'inp-btn'

    def __init__(self):
        self.driver = WDriver().get_driver()
        logger.info("selenum id:{}".format(id(self.driver)))

    def serach_book(self, keywords):
        '''
        搜索
        :param keywords:
        :return:
        '''
        logger.info("准备搜索的书名:{}".format(keywords))
        if self.driver.find_elements(*self._search_text):
            logger.info("查询到搜索")
        el = self.driver.find_element(*self._search_text)
        el.clear()
        el.send_keys(keywords)
        logger.info("搜索:{}".format(keywords))
        self.driver.back()
        logger.info("返回上一级")
Exemple #6
0
def pytest_runtest_makereport(item, call):
    '''
    hook pytest失败
    :param item:
    :param call:
    :return:
    '''
    # execute all other hooks to obtain the report object
    outcome = yield
    rep = outcome.get_result()
    # we only look at actual failing test calls, not setup/teardown
    if rep.when == "call" and rep.failed:
        mode = "a" if os.path.exists("failures") else "w"
        with open("failures", mode) as f:
            # let's also access a fixture for the fun of it
            if "tmpdir" in item.fixturenames:
                extra = " (%s)" % item.funcargs["tmpdir"]
            else:
                extra = ""
            f.write(rep.nodeid + extra + "\n")
        logger.info("测试失败了")
        with allure.step('添加失败截图...'):
            allure.attach(rep.nodeid, WDriver().get_driver().get_screenshot_as_png(),type=AttachmentType.PNG)
 def __init__(self):
     self.driver = WDriver().get_driver()
Exemple #8
0
 def __init__(self):
     self.driver = WDriver().get_driver()
     logger.info("selenum id:{}".format(id(self.driver)))
Exemple #9
0
 def __init__(self):
     logger.info("初始化HomePage")
     self.driver = WDriver().get_driver()
     self.func = FunctionPage()
Exemple #10
0
class HomePage():

    _home_serach = By.XPATH, '//*[@id="anony-nav"]/div[2]/form/span[1]/input'
    _home_serach_submit = By.XPATH, '//*[@id="anony-nav"]/div[2]/form/span[2]/input'
    _pwd_btn = By.CLASS_NAME, 'account-tab-account'
    _account = By.CLASS_NAME, 'account-form-input'
    _pwd = By.CLASS_NAME, 'password'
    _login_btn = By.CLASS_NAME, 'account-form-field-submit'
    _link_book = By.CLASS_NAME, 'lnk-book'
    _link_movie = By.CLASS_NAME, 'lnk-movie'
    _link_app = By.CLASS_NAME, 'lnk-app'
    _page = "#fp-nav > ul > li:nth-child({}) > a"

    def __init__(self):
        logger.info("初始化HomePage")
        self.driver = WDriver().get_driver()
        self.func = FunctionPage()
        # logger.info("selenum id:{}".format(id(self.driver)))

    def switch_to_login_frame(self):
        self.driver.switch_to.frame(
            self.driver.find_elements_by_tag_name("iframe")[0])
        logger.info("切换frame")

    def home_serach(self, keywords):
        '''
        首页搜索
        :return:
        '''
        self.driver.find_element(*self._home_serach).send_keys(keywords)
        self.driver.find_element(*self._home_serach_submit).send_keys(keywords)
        logger.info("首页搜索:{}".format(keywords))

    def home_pwd_login(self):
        '''
        首页密码登录
        :return:
        '''
        self.switch_to_login_frame()
        account_tab_account = self.driver.find_element(*self._pwd_btn)
        account_tab_account.click()
        self.driver.execute_script(
            "arguments[0].style.background = 'rgb(138,43,226 )';",
            account_tab_account)
        logger.info("点击密码登录...")
        time.sleep(3)

    def go_book(self):
        table_source = self.driver.find_element(
            *self._link_book).get_attribute('innerHTML')
        logger.info(table_source)
        # 获取按钮的文案
        self.driver.find_element(*self._link_book).click()
        logger.info("点击读书")
        self.func.switch_window()

    def go_movie(self):
        table_source = self.driver.find_element(
            *self._link_movie).get_attribute('innerHTML')
        logger.info(table_source)
        # 获取按钮的文案
        self.driver.find_element(*self._link_movie).click()
        logger.info("点击电影")
        self.func.switch_window()

    def download_app(self):
        self.driver.find_element(*self._link_app).click()
        logger.info("点击下载app")
        for n in range(1, 5):
            page = self._page.format(n)
            self.driver.find_element(By.CSS_SELECTOR, page).click()
Exemple #11
0
 def setUp(self):
     logger.info("父类初始化")
     self.driver = WDriver().init_driver()
     logger.info("selenum id:{}".format(id(self.driver)))
     self.driver.get("https://www.douban.com")
Exemple #12
0
 def __init__(self):
     logger.info("初始化LoginPage")
     self.driver = WDriver().get_driver()
     logger.info("selenum id:{}".format(id(self.driver)))