Replies: 4 comments 18 replies
-
Hello @ksdaftari, and thank you for your support! The import warnings
from seleniumbase import BaseCase
from seleniumwire import webdriver
class BaseTestCase(BaseCase):
def setUp(self):
super().setUp()
self.driver.close()
self.driver.quit()
warnings.simplefilter("ignore", category=DeprecationWarning)
self.driver = webdriver.Chrome()
def test_wire(self):
self.open('https://seleniumbase.io/w3schools/')
for request in self.driver.requests:
if request.response:
print(
request.url,
request.response.status_code,
request.response.headers['Content-Type']
) Running that code with
As seen above, you'll get access to SeleniumBase methods, while also having access to SeleniumWire functionality. The above example will spin up one extra browser before the wire browser, but the impact should be minimal on time. I do hesitate to make |
Beta Was this translation helpful? Give feedback.
-
Hello @mdmintz , I would like to mock multiple requests in same webpage. Current intercept example is working for one request at a time. Could you help me mocking multiple requests? I'm using seleniumbase and seleniumwire combined. Thanks to your example above! Adding more "If" conditions will lengthen the code here. Any alternative that could help me? def interceptor(request): driver.request_interceptor = interceptor |
Beta Was this translation helpful? Give feedback.
-
@ksdaftari, If you missed the announcement, there's now a direct selenium-wire integration with seleniumbase: pytest --wire Then See #1574 for all the details. You can even change the proxy settings in the middle of your tests: self.set_wire_proxy("SERVER:PORT")
self.set_wire_proxy("socks5://SERVER:PORT")
self.set_wire_proxy("USERNAME:PASSWORD@SERVER:PORT") Here's how it looks with from seleniumbase import BaseCase
class TestWire(BaseCase):
def test_wire_inside_class(self):
self.open("https://seleniumbase.io/demo_page")
for request in self.driver.requests:
print(request.url) Here's how it looks with the def test_wire_with_no_class(sb):
sb.open("https://seleniumbase.io/demo_page")
for request in sb.driver.requests:
print(request.url)
class TestWire:
def test_wire_inside_class(self, sb):
sb.open("https://seleniumbase.io/demo_page")
for request in sb.driver.requests:
print(request.url) Here's how it looks with the from seleniumbase import SB
with SB(wire=True) as sb:
sb.open("https://seleniumbase.io/demo_page")
for request in sb.driver.requests:
print(request.url) Here's how it looks with the from seleniumbase import Driver
driver = Driver(wire=True)
driver.get("https://seleniumbase.io/demo_page")
for request in driver.requests:
print(request.url)
|
Beta Was this translation helpful? Give feedback.
-
@yeroda the --uc and --wire integrations don’t play nicely together, so pick one to use with SeleniumBase. Some of the wire features are already included with SeleniumBase, such as setting the proxy with --proxy=server:port or --proxy=user:pass@server:port. |
Beta Was this translation helpful? Give feedback.
-
Hello, first off great work on this amazing library, has been incredibly helpful in making our FE automated testing at our company actually easy to maintain and iterate on!
I was wondering is it currently possible or potentially thoughts on allowing it easy to integrate other selenium libraries that can help enhance the functionality seleniumbase gives. one I am thinking of is one like selenium-wire: https://github.com/wkeeling/selenium-wire (which allows a realy nice interface for inspecting the requests and responses, dummy up responses, etc). My thought of how would allow this is to pull the more core seleniumbase additional/improved interface it adds on top of the selenium webdriver and make that class. I believe given many of the other selenium libraries doing something similar, this would allow to use multiple class inheritance to add the functionality of each of them together, or perhaps allowing to specify specific webdriver (so can use one defined in these other libraries) (forget if already able to do this in seleniumbase)?
My guess this likely out of scope for this project, but wanted to bring up idea/question as thought could potentially be cool addition/capability to seleniumbase
Beta Was this translation helpful? Give feedback.
All reactions