class TestBaiduSearch: config = WebConfig('test_demo_baidu') testdata = config.testdata['test_search_data'] @pytest.mark.parametrize('testdata', testdata) def testsarch(self, testdata, driver_headless): testresult = BaiduSearchBusiness(driver_headless).baidu_searching( testdata).text assert testdata in testresult
def __init__(self, _driver): self.title = _driver.title self._log = Logger() self._webconfig = WebConfig('test_demo_baidu') self._appconfig = self._webconfig.app_config # 'search': {'content_left': '#content_left'}} self._pageobj = self._webconfig.domelements['search'] self._driver = _driver # findelement(d, csselector, timeout, timeseq): self._findele = DomUntil.findelement
def __init__(self, _driver): self._log = Logger() self._webconfig = WebConfig('test_demo_baidu') self._appconfig = self._webconfig.app_config # {'baidu_Home': {'search': {'search_input': '.s_ipt', 'submit_btn': '.s_btn'}}} self._pageobj = self._webconfig.domelements['home'] self._driver = _driver # findelement(d, csselector, timeout, timeseq): self._findele = DomUntil.findelement self.title = _driver.title
import time import pytest from selenium import webdriver from Common.web_config_until import WebConfig t = time.strftime("%Y-%m-%d %H:%M:%S") driver_path = WebConfig('driver').get_appinfo()['Driver'] @pytest.fixture(scope='function') def con_database(): print('connecting database %s' % t) con_id = 1 return con_id @pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(item, call): pytest_html = item.config.pluginmanager.getplugin('html') outcome = yield report = outcome.get_result() extra = getattr(report, 'extra', []) if report.when == 'call': xfail = hasattr(report, 'wasxfail') if (report.skipped and xfail) or (report.failed and not xfail): screen = _capture_screenshot() extra.append(pytest_html.extras.png(screen)) # only add additional html on failure extra.append(pytest_html.extras.html('<div>Additional HTML</div>')) report.extra = extra
class BaiduSearch: def __init__(self, _driver): self.title = _driver.title self._log = Logger() self._webconfig = WebConfig('test_demo_baidu') self._appconfig = self._webconfig.app_config # 'search': {'content_left': '#content_left'}} self._pageobj = self._webconfig.domelements['search'] self._driver = _driver # findelement(d, csselector, timeout, timeseq): self._findele = DomUntil.findelement def content_left_firstele(self): css = self._pageobj['content_left'] ele = self._findele(self._driver, css, 5, 0.5) return ele if __name__ == '__main__': driver = WebConfig('test').get_driver driver.get('http://www.baidu.com') b = BaiduSearch(driver) bh = BaiduHome(driver) bh.search_bar_input('test') bh.submit_btn_click() _ele = b.content_left_firstele() assert 'test - 百度翻译' in _ele.text driver.quit()
def __init__(self, driver): self._log = Logger() self._home = BaiduHome(driver) self._search = BaiduSearch(driver) self._driver = driver self._url = WebConfig('test_demo_baidu').app_config['domain_url']
from Common.logger_until import Logger class BaiduSearchBusiness: def __init__(self, driver): self._log = Logger() self._home = BaiduHome(driver) self._search = BaiduSearch(driver) self._driver = driver self._url = WebConfig('test_demo_baidu').app_config['domain_url'] def baidu_searching(self, context): self._driver.get(self._url) self._log.logger(f'visiting {self._url}') self._home.search_bar_input(context) self._log.logger(f'inputing {context} to search bar') self._home.submit_btn_click() self._log.logger(f'Clicking submit btn') result = self._search.content_left_firstele() log_result = result.text self._log.logger(f'got the result as {log_result}') return result if __name__ == '__main__': w = WebConfig('test') _driver = w.get_driver_headless b = BaiduSearchBusiness(_driver) reslut_ele = b.baidu_searching('test') print(reslut_ele.text)