Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up`--cap-file=CAP_FILE` only works with tests that run on Selenium Grid #535
Comments
same question `node = <_ast.BinOp object at 0x10719c890>
E ValueError: malformed node or string: <_ast.BinOp object at 0x10719c890>` |
@aklajnert @tcw0nw What run commands are you using? If running locally, you must use a Selenium Grid, and you can start one up with two lines on the command line: seleniumbase grid-hub start
seleniumbase grid-node start Now you can run something like this from the pytest basic_test.py --server=127.0.0.1 --cap-file=capabilities/sample_cap_file_BS.py
=============================================== test session starts ================================================
platform darwin -- Python 3.7.0, pytest-5.3.5, py-1.8.0, pluggy-0.13.1
rootdir: /Users/michael/github/SeleniumBase, inifile: pytest.ini
plugins: timeout-1.3.4, html-2.0.1, rerunfailures-9.0, xdist-1.31.0, ordering-0.6, forked-1.1.3, metadata-1.8.0, cov-2.8.1, seleniumbase-1.36.9
collected 1 item
basic_test.py Starting ChromeDriver 2.44.609545 (c2f88692e98ce7233d2df7c724465ecacfe74df5) on port 44953
Only local connections are allowed.
.
================================================ 1 passed in 5.20s |
@mdmintz why the selenium grid is required here? The local driver should also have the ability to override the capabilities (which I did with an ugly hack). Here's my hack in case someone needs it: from selenium.webdriver.chrome.options import Options
to_capabilities = Options.to_capabilities
def new_to_capabilities(self):
capabilities = to_capabilities(self)
capabilities["goog:loggingPrefs"] = {"browser": "ALL"}
return capabilities
Options.to_capabilities = new_to_capabilities I would expect |
Can you see the complete code? |
@tcw0nw what do you mean? |
@aklajnert webdriver.Remote(command_executor, desired_capabilities, browser_profile) But it is not built natively into |
@mdmintz are you sure that didn't change? Here's a fragment of my class WebDriver(RemoteWebDriver):
"""
Controls the ChromeDriver and allows you to drive the browser.
You will need to download the ChromeDriver executable from
http://chromedriver.storage.googleapis.com/index.html
"""
def __init__(self, executable_path="chromedriver", port=0,
options=None, service_args=None,
desired_capabilities=None, service_log_path=None,
chrome_options=None, keep_alive=True):
... As you see, the |
@aklajnert Thank you. I'll look into it more and see what I can do. That does appear to be using RemoteWebDriver, and if you've explored Selenium 4 at all (beta is available), you'll see that |
@mdmintz got it, that's reasonable. For now, I'm good with the ugly monkey-patching. |
I changed the title since this works correctly when using a remote Selenium Grid such as Sauce Labs or Browserstack. seleniumbase grid-hub start
seleniumbase grid-node start
pytest MY_TEST.py --server="127.0.0.1" --browser=remote --cap-file=CAP_FILE |
Can self.get_new_driver be used for this purpose? It seems to allow you to provide cap_file in its params. However I wasn't able to get it to work correctly myself. It opens a new browser for me but my test doesn't make use of it and continue to open another browser instance for running tests. |
@q30 The cap_file still needs a Selenium Grid to process the desired capabilities right now. Changing this is on hold until Selenium 4 is officially released because that's going to simplify a lot of things related to this. Right now, SeleniumBase includes multiple command-line options that will let you set things without the cap file. But if you need the cap_file (which was orginally made to make it easier to use remote Selenium Grids like BrowserStack and Sauce Labs) then you can still easily spin up your own Selenium Grid with: |
Thank you @mdmintz! This helps. |
Currently, SeleniumBase has
cap_file
option, that doesn't seem to work.What I want to achieve is to add
{'goog:loggingPrefs': {'browser': 'ALL'}}
. Unfortunately, the only way I achieved that is by ugly monkey-patching around thewebdriver
.I've tried to set
cap_file
to file with something like below, but it didn't work. Actually nothing happened. There was no difference in capabilities with or without the file.My example
cap_file
:I've debugged the sources and it seems that the
get_local_driver()
method doesn't use the file at all.