Skip to content

Add support for https protocol for Remote drivers - #272

Merged
BeyondEvil merged 2 commits into
pytest-dev:masterfrom
platonoff-dev:https-support
Apr 4, 2022
Merged

BeyondEvil merged 2 commits into
pytest-dev:masterfrom
platonoff-dev:https-support

Conversation

@platonoff-dev

Copy link
Copy Markdown
Contributor

Fix #266

@isaulv

isaulv commented Sep 2, 2021

Copy link
Copy Markdown
Contributor

Did you test with selenium 4.0.0?

@platonoff-dev

Copy link
Copy Markdown
Contributor Author

Yep. Looks like it work good with 4.0.0

Comment thread testing/test_driver.py Outdated
testdir.quick_qa("--driver", "Remote", file_test, passed=1)


def test_https_host_port(testdir):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@platonoff-dev You added a check for https and no protocol but shouldn't you also test the case for http protocol?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think test_default_host_port does the same...

def test_default_host_port(testdir):

@dosas dosas Sep 20, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I don't think so that is another case where the protocol is not explicitly given:

host expected url tested
https://... https://... yes
http://... http://... no
no.protocol http://no.protocol yes
localhost http://localhost yes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I hurried with this a little

@dosas dosas Sep 20, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I think this can be solved with a simple parametrization: http, https

Writing this I realize that all of these tests (mentioned in the table) could probably be parametrized to one test

Comment thread pytest_selenium/drivers/remote.py Outdated
@@ -9,7 +9,9 @@


def driver_kwargs(capabilities, firefox_profile, host, port, **kwargs):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also fix this for the appium driver:

executor = "http://{0}:{1}/wd/hub".format(host, port)
?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I forgot about appium 😅 I'll do that


def driver_kwargs(capabilities, firefox_profile, host, port, **kwargs):
executor = "http://{0}:{1}/wd/hub".format(host, port)
executor = f"{host}:{port}/wd/hub"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@platonoff-dev I know that this is totally valid and working code but what about:

protocol = "" if re.search(r"^https?://", host) else "http://"
executor = f"{protocol}{host}:{port}/wd/hub

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with that. It's one of my problems 😅. I thought about that, but decided that my solution is more kind for new developers. They faster understand my version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But your suggestion looks cleaner. I'll change that

@dosas dosas Sep 20, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the regexp though ... if it makes it cleaner or slower (due to import)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❯ python test_performance.py
regexp: 0.009595889999999996
if: 0.004040118000000002

Almost two times slower...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code that I ran:

import re
import timeit


def regexp_search():
    host = "https://some.host.com"
    port = "4444"
    protocol = "" if re.search(r"^https?://", host) else "http://"
    executor = f"{protocol}{host}:{port}/wd/hub"


def if_search():
    host = "https://some.host.com"
    port = "4444"
    executor = f"{host}:{port}/wd/hub"
    if not executor.startswith("http://") and not executor.startswith("https://"):
        executor = "http://" + executor


if __name__ == "__main__":
    print("regexp:", timeit.timeit(regexp_search, number=10000))
    print("if:", timeit.timeit(if_search, number=10000))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thanks for testing that! I think that settles it then :D

@BeyondEvil

Copy link
Copy Markdown
Contributor

Thanks for your contribution @platonoff-dev ! 🙏

Also, thanks to @dosas for the help! 🙏

Sorry it took me so long to look at it. :(

What about this:

def driver_kwargs(capabilities, firefox_profile, host, port, **kwargs):
    host = host if host.startswith("http") else f"http://{host}" 
    executor = "{0}:{1}/wd/hub".format(host, port)

    kwargs = {
        "command_executor": executor,
        "desired_capabilities": capabilities,
        "browser_profile": firefox_profile,
    }
    return kwargs

It's backwards compatible and if the user wants to use https, they simply provide the fully qualified url.

Thoughts?

@platonoff-dev

Copy link
Copy Markdown
Contributor Author

I fixed it in my project with monkey patching and now it looks like this in my project :)
image
And I really forgot about this PR.

So, your suggestion looks great. But during fix in my project, I remembered a few new things:

  1. Port is not required. https://some.hub.com/wd/hub is a valid URL. With current realization It can be handled with specifying 443 or 80 explicit. But it looks ugly.
  2. Also, path can be different from /wd/hub

@dosas

dosas commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

I do not know about the requirements, I just reviewed it based on what I thought the code should do and suggested missing tests based on possible combinations/scenarios.

@dosas

dosas commented Nov 15, 2021

Copy link
Copy Markdown
Contributor

@platonoff-dev Any news on this?

@platonoff-dev

platonoff-dev commented Nov 16, 2021 •

Copy link
Copy Markdown
Contributor Author

Oh, I completely forgot about this again( Yeah, I'll push required changes tomorrow.

@platonoff-dev

Copy link
Copy Markdown
Contributor Author

@dosas Fixed all review remarks
It was a hard week and only now it turned out to be done)

Comment thread testing/test_driver.py
"Remote",
"--selenium-host",
host,
"--selenium-port",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since 4444 is the default there is no need to explicitly pass it here but fine for me.

dosas
dosas previously approved these changes Dec 1, 2021
@platonoff-dev

Copy link
Copy Markdown
Contributor Author

Any changes I need to do?

@BeyondEvil

Copy link
Copy Markdown
Contributor

Thanks for reminding me @platonoff-dev I don't think so at this point. I need to do some other work first, however. I apologise for the delay!

@BeyondEvil

BeyondEvil commented Mar 28, 2022 •

Copy link
Copy Markdown
Contributor

I tried to help out by rebasing the branch, but I couldn't figure out how to do it. 🤷‍♂️

@platonoff-dev

@BeyondEvil

Copy link
Copy Markdown
Contributor

Once this PR is merged, i can continue with: #293

@platonoff-dev

Copy link
Copy Markdown
Contributor Author

@BeyondEvil Ohh, I see it. But how can I do it? I have no write access, so I can't resolve it here. Just one option I can see is to rebase master into https-support and resolve conflict locally and then push. Is it ok?

@BeyondEvil

BeyondEvil commented Apr 4, 2022 •

Copy link
Copy Markdown
Contributor

@BeyondEvil Ohh, I see it. But how can I do it? I have no write access, so I can't resolve it here. Just one option I can see is to rebase master into https-support and resolve conflict locally and then push. Is it ok?

Yes, that's exactly how you do it. 😊 👍

$ git pull --rebase upstream master

(if you named the upstream "upstream" that is 😊 )

@platonoff-dev

@BeyondEvil

Copy link
Copy Markdown
Contributor

I think something went wrong with the rebase @platonoff-dev 😬

@platonoff-dev

Copy link
Copy Markdown
Contributor Author

Yeah 😬 Give me few minutes

@platonoff-dev

Copy link
Copy Markdown
Contributor Author

@BeyondEvil looks like black in pre-commit is broken

@BeyondEvil

BeyondEvil commented Apr 4, 2022 •

Copy link
Copy Markdown
Contributor

Did you run pre-commit locally?

It looks like Flake8 complains about: testing/test_driver.py:149:1: F811 redefinition of unused 'test_host_protocol' from line 118

@platonoff-dev

@platonoff-dev

Copy link
Copy Markdown
Contributor Author

This one is already fixed

@BeyondEvil

Copy link
Copy Markdown
Contributor

This one is already fixed

Does pre-commit pass for you locally?

@BeyondEvil

Copy link
Copy Markdown
Contributor

psf/black#2984

@platonoff-dev

Copy link
Copy Markdown
Contributor Author

No, to commit fix I've used --no-verify. I wasn't sure if I should update black version here

@BeyondEvil

Copy link
Copy Markdown
Contributor

No, to commit fix I've used --no-verify. I wasn't sure if I should update black version here

Sure, go ahead.

BeyondEvil
BeyondEvil previously approved these changes Apr 4, 2022

@BeyondEvil BeyondEvil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@BeyondEvil

BeyondEvil commented Apr 4, 2022 •

Copy link
Copy Markdown
Contributor

Nice! Almost there!

Can you squash/rebase all the commits to only relevant ones? (probably two, one for the https changes and one for the black bump). 🙏 🙇

Anatoliy Platonov and others added 2 commits April 4, 2022 17:42
Keep protocol if specified for apium too. Fix tests

Add support for https protocol for Remote drivers

Keep protocol if specified for apium too. Fix tests

Remove duplicate of test
@platonoff-dev

Copy link
Copy Markdown
Contributor Author

@BeyondEvil done

@BeyondEvil BeyondEvil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@BeyondEvil
BeyondEvil merged commit 5ba7a42 into pytest-dev:master Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTPS support for remote driver

4 participants