def open_browsr(host, browser): """启动指定节点指定浏览器""" driver = Remote(command_executor=host, desired_capabilities={ 'platform': 'ANY', 'browserName': browser, 'version': '', 'javascriptEnabled': True }) driver.get('https://www.baidu.com/') driver.find_element_by_id('kw').send_keys('python') driver.find_element_by_id('su').click() time.sleep(2) driver.quit()
def setUp(self): browser = os.environ.get('BROWSER', 'CHROME') self.driver = Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=getattr( DesiredCapabilities, browser).copy()) self.driver.implicitly_wait(5) auth_page = AuthPage(self.driver) auth_page.open() auth_form = auth_page.form auth_form.set_login(LOGIN) auth_form.set_password(PASSWORD) auth_form.submit() GroupsPage(self.driver).open()
def __init__(self, url=DEFAULT_URL, browser='firefox', wait_time=2, **ability_args): abilities = getattr(DesiredCapabilities, browser.upper(), {}) for arg in ability_args: ability_args[arg] = ability_args[arg] self.driver = Remote(url, abilities) self.element_class = WebDriverElement self._cookie_manager = CookieManagerAPI() super(WebDriver, self).__init__(wait_time)
def get_sauce_driver(self): desired_cap = { 'platform': 'Mac OS X 10.9', 'browserName': 'chrome', 'version': '31', 'tags': ['ui'] } sauceUrl = 'http://%s:%[email protected]:80/wd/hub' \ % (USERNAME, ACCESS_KEY) driver = Remote( command_executor=sauceUrl, desired_capabilities=desired_cap) return driver
def admin(): rendered = '' if request.method == 'POST': url = request.form.get('url') or '' try: browser = Remote('http://selenium:4444/wd/hub', DesiredCapabilities.CHROME) # TODO: Replace with appropriate hostname and port browser.get(HOST) browser.add_cookie({'name': 'session', 'value': request.cookies.get('session')}) browser.get(url) renderer_wait_js(browser) rendered = browser.page_source except Exception as e: pass return render_template('authenticated/admin.html', rendered=rendered)
def __init__(self, url=DEFAULT_URL, browser="firefox", wait_time=2, **ability_args): browsername = browser.upper() # Handle case where user specifies IE with a space in it if browsername == "INTERNET EXPLORER": browsername = "INTERNETEXPLORER" abilities = getattr(DesiredCapabilities, browsername, {}) abilities.update(ability_args) self.driver = Remote(url, abilities) self.element_class = WebDriverElement self._cookie_manager = CookieManager(self.driver) super(WebDriver, self).__init__(wait_time)
def setUp(self): self.driver_1 = Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME) self.driver_1.implicitly_wait(10) self.driver_2 = Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME) self.driver_2.implicitly_wait(10) auth_page = AuthPage(self.driver_1) auth_page.open() profile_page = auth_page.sign_in(self.LOGIN_1, self.PASSWORD_1) desc = { 'description': 'group about shit', 'title': 'pulp fiction', 'subcategory': GroupSubcategory.CINEMA_TV, 'age_restriction': AgeRestriction.NO_RESTRICTION } group_page = profile_page.to_groups_page().create_public_page(desc) group_page.open() auth_page_user2 = AuthPage(self.driver_2) auth_page_user2.open() profile_user_2 = auth_page_user2.sign_in(self.LOGIN_2, self.PASSWORD_2) group_page_user2 = GroupPage(self.driver_2, path=group_page.path).open() setting_page = group_page.to_settings_page() self.group_page = group_page self.group_page_user_2 = group_page_user2 self.setting_page = setting_page self.profile_user_2 = profile_user_2
def browser_L_5557_firefox(): lists = {'http://127.0.0.1:5557/wd/hub':'firefox'} for host, browser in lists.items(): print(host, browser) driver= Remote(command_executor=host, desired_capabilities={'platform':'ANY', 'browserName':browser, 'version':'', 'javascriptEnabled':True } ) return driver
def setUp(self) -> None: browser = os.environ.get('BROWSER', 'CHROME') self.driver = Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=getattr( DesiredCapabilities, browser).copy()) LOGIN = os.environ['LOGIN'] PASSWORD = os.environ['PASSWORD'] auth_page = AuthPage(self.driver) auth_page.auth(LOGIN, PASSWORD) id_page = Main_page(self.driver) id_page.open(id_page.BASE_URL) self.data_page = Data_page(self.driver) self.main_page = Main_page(self.driver)
def browser(): """ 全局定义浏览器驱动 :return: """ global driver global driver_type if driver_type == "chrome": # 本地chrome浏览器 option = webdriver.ChromeOptions() option.add_argument("disable-infobars") path = "D:\\PyCharm\\workspace\\webdriver\\75.0.3770.90\\chromedriver.exe" driver = webdriver.Chrome(options=option, executable_path=path) driver.maximize_window() # driver.set_window_size(1920, 1080) elif driver_type == "firefox": # 本地firefox浏览器 driver = webdriver.Firefox() driver.set_window_size(1920, 1080) elif driver_type == "chrome-headless": # chrome headless模式 chrome_options = CH_Options() chrome_options.add_argument("--headless") chrome_options.add_argument('--disable-gpu') chrome_options.add_argument("--window-size=1920x1080") driver = webdriver.Chrome(options=chrome_options) elif driver_type == "firefox-headless": # firefox headless模式 firefox_options = FF_Options() firefox_options.headless = True driver = webdriver.Firefox(firefox_options=firefox_options) elif driver_type == "grid": # 通过远程节点运行 driver = Remote(command_executor='http://10.2.16.182:4444/wd/hub', desired_capabilities={ "browserName": "chrome", }) driver.set_window_size(1920, 1080) else: raise NameError("driver驱动类型定义错误!") return driver
def setUp(self): browser = os.environ.get('BROWSER', 'CHROME') self.driver = Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=getattr( DesiredCapabilities, browser).copy()) AddressPage(self.driver).open() storage = LocalStorage(self.driver) storage.set('deliveryGeo', self.ADDRESS) storage.set('longitude', self.LONGITUDE) storage.set('latitude', self.LATITUDE) self.driver.implicitly_wait(2) self.driver.refresh() self.driver.maximize_window() main_page = MainPage(self.driver) main_page.wait_visible() main_page.auth(self.LOGIN, self.PASSWORD) self.filler = DatabaseFiller() self.filler.user_auth() self.user_id = self.filler.get_profile_id() self.filler.admin_auth() self.filler.create_test_restaurants(1) self.filler.create_products_for_rests(1, 100) self.rest_id = self.filler.get_restaurant_id_by_name( self.filler.TEST_REST_NAME.format(0)) self.rest_list_page = AdminRestaurantsPage(self.driver) products = self.filler.get_restaurant_products( self.filler.TEST_REST_NAME.format(0)) self.filler.create_order(self.user_id, self.filler.TEST_REST_NAME.format(0), self.LOGIN, products[0]) self.rest_list_page.open() self.rest_list_page.wait_visible() self.rest_list_page.open_manage_orders(self.rest_id) self.form = self.rest_list_page.manage_orders_form self.form.wait_visible()
def browser(): """ 全局定义浏览器驱动 :return: """ global driver global driver_type if driver_type == "chrome": # 本地chrome浏览器 option = webdriver.ChromeOptions() option.add_argument('--headless') option.add_argument('--disable-gpu') option.add_argument("user-agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108-1 Safari/537.36'") driver = webdriver.Chrome(chrome_options=option,executable_path="/opt/google/chrome/chromedriver") driver.set_window_size(1920, 1080) elif driver_type == "firefox": # 本地firefox浏览器 driver = webdriver.Firefox() driver.set_window_size(1920, 1080) elif driver_type == "chrome-headless": # chrome headless模式 chrome_options = CH_Options() chrome_options.add_argument("--headless") chrome_options.add_argument('--disable-gpu') chrome_options.add_argument("--window-size=1920x1080") driver = webdriver.Chrome(options=chrome_options) elif driver_type == "firefox-headless": # firefox headless模式 firefox_options = FF_Options() firefox_options.headless = True driver = webdriver.Firefox(firefox_options=firefox_options) elif driver_type == "grid": # 通过远程节点运行 driver = Remote(command_executor='http://10.2.16.182:4444/wd/hub', desired_capabilities={ "browserName": "chrome", }) driver.set_window_size(1920, 1080) else: raise NameError("driver驱动类型定义错误!") return driver
def test_hub_node(self): self.driver = Remote(self.available_node['node1'][0], desired_capabilities={ 'platform': 'ANY', 'browserName': self.available_node['node1'][1], 'version': '', 'javascriptEnabled': True }) #Rome 的用法如上,被操作的端口,平台,浏览器,平台版本,要通过hub调动node必需是能javascriptEnabled:True self.driver.implicitly_wait(30) driver = self.driver driver.get(self.base_url) driver.find_element_by_id("kw").send_keys("remote") driver.find_element_by_id("su").click() time.sleep(5)
def test_open_driver(self,host,brower): driver = Remote(command_executor=host, desired_capabilities=brower ) # fileList = fileRead().get_ip_address() # ipAdd = fileList[0].strip('\n') driver.maximize_window() driver.get("https://" + ipAdd + "/fort") if brower == DesiredCapabilities.INTERNETEXPLORER: #https访问时弹出安全警告页面后点击继续,0代表有安全警告,1代表没有安全警告 driver.get("javascript:document.getElementById('overridelink').click();") #获取浏览器版本 #brower_name = DesiredCapabilities.INTERNETEXPLORER.get('browserName') return driver
def setUp(self): browser = os.environ.get('BROWSER', 'FIREFOX') self.driver = Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=getattr( DesiredCapabilities, browser).copy()) auth_page = AuthPage(self.driver) auth_page.open() auth_form = auth_page.form auth_form.set_login(self.USEREMAIL) auth_form.set_password(self.PASSWORD) auth_form.submit() self.main_page = MainPage(self.driver) self.main_page.waitForVisible()
def __init__(self, url, usuario, senha): options = ChromeOptions() preferecias = { "download.default_directory": DIRETORIO, "safebrowsing.enabled": "false", } options.add_experimental_option("prefs", preferecias) options.add_argument("--ignore-certificate-errors") options.add_argument("--start-maximized") # browser = Chrome(options=options) browser = Remote( # command_executor= 'http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME, options=options, ) super().__init__(url, usuario, senha, browser)
def setUp(self): self.driver = Remote( command_executor="http://localhost:4444/wd/hub", desired_capabilities=getattr(DesiredCapabilities, self.BROWSER_NAME).copy() ) self.page = AuthPage(self.MAIL_URL, self.driver) self.page.open() self.page.get_form.authenticate(self.EMAIL, self.PASSWORD) self.page = MailPage(self.MAIL_URL, self.driver) self.page.open() self.page.switch_to_ab() self.page = ABPage(self.ADDRESSBOOK_URL, self.driver)
def cli_main(): """cli entrypoitns, sets up everything needed""" SearchContext.commit() args = parser.parse_args() # open up a browser firefox_remote = Remote("http://127.0.0.1:4444/wd/hub", DesiredCapabilities.FIREFOX) with contextlib.closing(firefox_remote): context = SearchContext.from_instances([FastSearch(), Browser(firefox_remote)]) search = Search(parent=context) if args.fast: with context.use(FastSearch, Browser): main(search, args.query) else: with context.use(Browser): main(search, args.query)
def setup(self): browser = os.environ.get('BROWSER', 'FIREFOX') self.driver = Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=getattr( DesiredCapabilities, browser).copy()) auth_page = AuthPage(self.driver) auth_page.open() auth_form = auth_page.form auth_form.open_form() auth_form.set_login(self.USERLOGIN) auth_form.set_password(self.PASSWORD) auth_form.submit() user_name = auth_page.user_block.get_username() self.assertion.equal(user_name, self.USERNAME)
def setUp(self): # self.driver = webdriver.Chrome() # self.driver.implicitly_wait(30) # self.base_url = "http://192.168.2.87" command_executor = 'http://192.168.2.35:8012/wd/hub' desired_capabilities = { 'platform': 'ANY', 'browserName': 'chrome', 'version': '', 'javascriptEnabled': True } self.driver = Remote(command_executor, desired_capabilities) self.driver.implicitly_wait(30) self.base_url = "http://192.168.2.87" driver = self.driver logging.info("打开浏览器成功")
def browser(self, driver): """ Define global browser driver :return: """ if driver == "chrome": driver = webdriver.Chrome() driver.maximize_window() logger.info("启动chrome浏览器") elif driver == "firefox": driver = webdriver.Firefox() driver.maximize_window() logger.info("启动firefox浏览器") elif driver == "IE": driver = webdriver.Ie() driver.maximize_window() logger.info("启动IE浏览器") elif driver == "chrome-headless": chrome_options = CH_Options() chrome_options.add_argument("--headless") chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--window-size=1920x1080") driver = webdriver.Chrome(chrome_options=chrome_options) logger.info("启动Chrome headless浏览器") elif driver == "firefox-headless": firefox_options = FF_Options() firefox_options.headless = True driver = webdriver.Firefox(firefox_options=firefox_options) elif driver == "grid": #Remote selenium grid driver = Remote(command_executor='http://10.12.16.118:4444/wd/hub', desired_capabilities={ "browserName": "chrome", }) driver.maximize_window() else: raise NameError("driver驱动类型定义错误!") driver.implicitly_wait(5) logger.info("设置5秒隐式等待") return driver
def setUp(self): browser = os.environ.get('BROWSER', os.environ['BROWSER']) self.driver = Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=getattr( DesiredCapabilities, browser).copy()) self.gift_page = GiftPage(self.driver) self.self_gift = SelfGiftPage(self.driver) self.gift_dialog_page = GiftDialogPage(self.driver) self.gift_page.open() self.gift_page.open_self_gifts() if not self.gift_page.check_gift_exist(): self.gift_page.create_new_gift() self.gift_page.open_without_auth()
def setUp(self): browser = os.environ.get('BROWSER', 'CHROME') self.driver = Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=getattr( DesiredCapabilities, browser).copy()) self.accountSteps = AccountSteps(self.driver) self.folderSteps = FoldersSteps(self.driver) self.accountSteps.login(os.environ['LOGIN'], os.environ['PASSWORD']) self.__password_context = { 'password': '******', 're_password': '******', 'question': 'why?', 'question_answer': 'because', 'current_password': os.environ['PASSWORD'] }
def remote_open_driver(self,host,brower): driver = Remote(command_executor=host, desired_capabilities={'platform':'ANY', 'browserName':brower, # 'version':'', 'javascriptEnabled':True, 'marionette':False } ) ipAdd = jsonTranscoding().get_app_ip().strip() driver.maximize_window() driver.get("https://" + ipAdd + "/fort") if brower == "internet explorer": #https访问时弹出安全警告页面后点击继续,0代表有安全警告,1代表没有安全警告 driver.get("javascript:document.getElementById('overridelink').click();") return driver
def browser(): host = '172.16.2.18:4444' #运行主机:端口号 #这里可以参数化配置 driver = Remote(command_executor='http://'+host+'/wd/hub', desired_capabilities={ 'platform':'ANY', 'browserName':'firefox', 'version':'', 'javascriptEnabled':True } ) return driver # if __name__ == '__main__': # dr = browser() # dr.get('http://www.baidu.com') # dr.quit()
def get_tokens(self): chrome_options = Options() chrome_options.add_argument('--headless') if self.remote: driver = Remote( command_executor=self.selenium_server_url, desired_capabilities=chrome_options.to_capabilities()) else: driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options) driver.get('http://twitter.com') gt = driver.get_cookie('gt')['value'] self.config.update({'tw_guest_token': gt}) write_json_to_file('resources/config.json', dump(self.config)) logging.info(f'Получен новый токен: {gt}') driver.quit() return gt
def browser(): """ 启动浏览器驱动 :return: 返回浏览器驱动URL """ try: host = '127.0.0.1:4444' driver = Remote(command_executor='http://' + host + '/wd/hub', desired_capabilities={ 'platform': 'ANY', 'browserName': 'chrome', 'version': "", 'javascriptEnabled': True }) return driver except Exception as msg: print("驱动异常-> {0}".format(msg))
def driver(): """ Selenium driver fixture """ # Start a selenium server running chrome capabilities = DesiredCapabilities.CHROME.copy() capabilities['chromeOptions'] = { 'binary': os.getenv('CHROME_BIN', '/usr/bin/google-chrome-stable'), 'args': ['--no-sandbox'], } driver = Remote( os.getenv('SELENIUM_URL', 'http://chrome:5555/wd/hub'), capabilities, ) driver.implicitly_wait(10) yield driver driver.close()
def driver(self): """ 启动浏览器驱动 :return: 返回浏览器驱动URL """ try: # driver = webdriver.Chrome() driver = Remote(command_executor='http://' + self.host + '/wd/hub', desired_capabilities={ 'platform': 'ANY', 'browserName': self.browser, 'version': "", 'javascriptEnabled': True }) return driver except Exception as msg: print("驱动异常-> {0}".format(msg))
def driver(): """ 全局定义浏览器驱动 :return: """ global dr if driver_type == "chrome": # 本地chrome浏览器 dr = SD.Chrome() dr.maximize_window() elif driver_type == "firefox": # 本地firefox浏览器 dr = SD.Firefox() dr.maximize_window() elif driver_type == "chrome-headless": # chrome headless模式 chrome_options = CH_Options() chrome_options.add_argument("--headless") chrome_options.add_argument('--disable-gpu') chrome_options.add_argument("--window-size=1920x1080") dr = SD.Chrome(options=chrome_options) elif driver_type == "firefox-headless": # firefox headless模式 firefox_options = FF_Options() firefox_options.headless = True dr = SD.Firefox(firefox_options=firefox_options) elif driver_type == "grid": # 通过远程节点运行 dr = Remote(command_executor='http://10.2.16.182:4444/wd/hub', desired_capabilities={ "browserName": "chrome", }) dr.maximize_window() elif driver_type == "app": # appium dr = AD.Remote("http://localhost:4723/wd/hub", caps) CommonPage(dr).skip_welcome_page() else: raise NameError("driver驱动类型定义错误!") return dr