def before_scenario(context, scenario): """Prepare context for scenario.""" if 'browser.firefox' in scenario.tags: driver_name = 'firefox' elif 'browser.chrome' in scenario.tags: driver_name = 'chrome' else: driver_name = getattr(settings, 'BDD_DEFAULT_BROWSER', 'chrome') params = { 'driver_name': driver_name, 'headless': getattr(settings, 'BDD_HEADLESS_BROWSER', False), 'incognito': getattr(settings, 'BDD_INCOGNITO_BROWSER', False), 'wait_time': getattr(settings, 'BDD_DEFAULT_WAIT_TIME', 5), 'fullscreen': getattr(settings, 'BDD_FULLSCREEN_BROWSER', False), } language = { 'intl.accept_languages': getattr( settings, 'BDD_BROWSER_LANGUAGE', 'en-US' ) } if driver_name == 'firefox': params.update({ 'profile_preferences': language, 'capabilities': {'moz:webdriverClick': False}, }) elif driver_name == 'chrome': load_entry_point('chromedriver-binary==74.0.3729.6.0', 'console_scripts', 'chromedriver-path') options = Options() options.add_experimental_option('prefs', language) params.update({ 'options': options }) context.browser = Browser(**params)
def before_scenario(context, scenario): """Prepare context for scenario.""" if 'browser.firefox' in scenario.tags: driver_name = 'firefox' elif 'browser.chrome' in scenario.tags: driver_name = 'chrome' else: driver_name = getattr(settings, 'BDD_DEFAULT_BROWSER', 'chrome') params = { 'driver_name': driver_name, 'headless': getattr(settings, 'BDD_HEADLESS_BROWSER', False), 'incognito': getattr(settings, 'BDD_INCOGNITO_BROWSER', False), 'wait_time': getattr(settings, 'BDD_DEFAULT_WAIT_TIME', 5) } language = { 'intl.accept_languages': getattr(settings, 'BDD_BROWSER_LANGUAGE', 'en-US') } if driver_name == 'firefox': params.update({ 'profile_preferences': language, 'capabilities': { 'moz:webdriverClick': False }, }) elif driver_name == 'chrome': load_entry_point('chromedriver-binary==2.37.0', 'console_scripts', 'chromedriver-path') options = Options() options.add_experimental_option('prefs', language) params.update({'options': options}) context.browser = Browser(**params)
def __init__(self, width = 500, height = 300): """ 抖音App视频下载 """ # 无头浏览器 chrome_options = Options() chrome_options.add_argument('user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"') self.driver = Browser(driver_name='chrome', executable_path='D:/chromedriver', options=chrome_options, headless=True)
def __init__(self, width=500, height=300): """ 抖音App视频下载 """ # 无头浏览器 chrome_options = Options() chrome_options.add_argument( 'user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"' )
def __init__(self, width = 500, height = 300): """ 抖音视频下载 :param width: :param height: """ chrome_options = Options() chrome_options.add_argument('user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"') self.driver = Browser(driver_name='chrome', executable_path='D:\Program Files\Python3\Scripts\chromedriver.exe', options=chrome_options, headless=True)
def __init__(self, addr, browser_window_size=(1920, 1080), page_load_timeout=30, sticky_timeout=30): setupterm() if os.path.isfile('/.docker'): # xvfb wrapper starting print('Using Xvfb') kwargs = {} if 'XVFB_WIDTH' in os.environ: kwargs['width'] = os.environ['XVFB_WIDTH'] if 'XVFB_HEIGHT' in os.environ: kwargs['height'] = os.environ['XVFB_HEIGHT'] self.xvfb = Xvfb(**kwargs) self.xvfb.start() options = Options() options.add_argument('--no-sandbox') self.browser = Browser('chrome', headless=False, options=options, wait_time=30, executable_path='./drivers/chromedriver') self.browser.driver.implicitly_wait(sticky_timeout) self.browser.driver.set_page_load_timeout(page_load_timeout) self.browser.driver.set_window_size(*browser_window_size) self.browser.visit(addr) self._failed_number = 0 self._succeeded_number = 0 self._red = tparm(tigetstr('setaf'), 1).decode('utf8') self._green = tparm(tigetstr('setaf'), 2).decode('utf8') self._reset = tparm(tigetstr('sgr0')).decode('utf8') self._pre_test_cases = [] self._test_cases = [] self._post_test_cases = [] for method in self.__ordered__: # pylint: disable=no-member if method.startswith('test_'): self._test_cases.append(method)
def setproxy(self): if self.proxy_info: [host, port] = self.proxy_info.split(":") if self.webdriver == 'firefox': proxy_settings = { 'network.proxy.type': 1, 'network.proxy.http': host, 'network.proxy.http_port': int(port), 'network.proxy.ssl': host, 'network.proxy.ssl_port': int(port), 'network.proxy.socks': host, 'network.proxy.socks_port': int(port), 'network.proxy.ftp': host, 'network.proxy.ftp_port': int(port) } return proxy_settings elif self.webdriver == 'chrome': chrome_options = Options() chrome_options.add_argument('--proxy-server=http://%s' % self.proxy_info) return chrome_options else: return None
def __init__(self, keyword): self.url = "https://www.amazon.com" self.name = "".join(random.sample(string.ascii_letters + string.digits, 6)) self.email = "".join(random.sample(string.ascii_letters + string.digits, 16)) + "@163.com" self.password = "".join(random.sample(string.ascii_letters + string.digits, 8)) self.keyword = keyword self.chrome_options = Options() logging.basicConfig(filename='amazon.log', level=logging.DEBUG) self.conn = pymysql.connect(host='192.168.0.211', port=6033, user='******', password='******', db='amazon') self.cs = self.conn.cursor() self.cs.execute('select id,ip,port from register_proxy_ips where is_alived = 1 order by id desc limit 1') self.proxy_ip = self.cs.fetchone() self.cs.execute('update register_proxy_ips set is_alived = 0 where id = %s' % self.proxy_ip[0]) self.conn.commit() logging.debug(self.proxy_ip) # self.chrome_options.add_argument('--proxy-server=http://{host}:{port}'.format(host=self.proxy_ip[1], port=self.proxy_ip[2])) self.browser = Browser('chrome', user_agent=generate_user_agent(device_type='desktop'))
def __init__(self): options = Options() # options.add_argument('--disable-accelerated-2d-canvas') options.add_argument('--disable-gpu') options.add_argument('--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36') self.browser = Browser("chrome", options=options)
def __init__(self, width = 500, height = 300): # 无头浏览器 chrome_options = Options() chrome_options.add_argument('user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"') self.driver = Browser(driver_name='chrome', executable_path='D:/chromedriver', options=chrome_options, headless=True)