wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.89k stars 249 forks source link

'SubRequest' object has no attribute 'headers' #487

Open RuslanBM opened 2 years ago

RuslanBM commented 2 years ago

Hi, thanks for service.

I'am using pytest-selenium to setting up browser start:

import pytest
@pytest.fixture
def selenium(selenium):
    selenium.implicitly_wait(10)
    selenium.maximize_window()
    return selenium

https://pytest-selenium.readthedocs.io/en/latest/user_guide.html#specifying-capabilities

And PageObject model to open pages, without setting up driver. https://selenium-python.readthedocs.io/page-objects.html

And starting like:

pytest

with pytest.ini

[pytest]
addopts = --driver Remote
          --verbose
          --tb short
          --selenium-port 4444
          --capability browserName chrome

and selenium remote in docker:

services:
    hub:
        image: selenium/hub:3.141.59-20200409
        ports:
            - "4444:4444"
    chrome_one:
        image: selenium/node-chrome-debug:latest
        volumes:
            - /dev/shm:/dev/shm
            - logs:/e2e/tests/logs
            - uploads:/e2e/tests/uploads:ro
        depends_on:
            - hub
            - tor
        environment:
            - HUB_HOST=hub
        ports:
            - 5901:5900

Finally, I got an error, could you please help to resolve it?

tests/functional/conftest.py:53: in interceptor
    request.headers['New-Header'] = 'Some Value'
E   AttributeError: 'SubRequest' object has no attribute 'headers'
wkeeling commented 2 years ago

Thanks for raising this. The issue is likely going to be caused by the fact that pytest-selenium isn't importing the driver from the seleniumwire.webdriver package, meaning that the request capture/interception API won't be available. I'll have a look at reproducing and see whether we can find a workaround.

RuslanBM commented 2 years ago

Do you have some good news? @wkeeling