Skip to content

Feature/selenium 4#338

Closed
LerryAlexander wants to merge 18 commits intobudtmo:masterfrom
LerryAlexander:feature/selenium_4
Closed

Feature/selenium 4#338
LerryAlexander wants to merge 18 commits intobudtmo:masterfrom
LerryAlexander:feature/selenium_4

Conversation

@LerryAlexander
Copy link
Copy Markdown
Contributor

@LerryAlexander LerryAlexander commented Jan 4, 2023

Purpose of changes

Currently, docker-android doesn't support the selenium grid with the newest architecture of Selenium 4, which means the selenium grid architecture has changed too, so in order to be able to use the new grid 4 architecture I'm proposing this PR which contains the following main changes:

Files:

  • src/app.py: added code logic to accept new node connections using the Selenium Grid 4 architecture when the environment variable CONNECT_TO_GRID_4=true.
  • src/run_app.sh: new file added before running python -m src.app to install all dependencies for running python with toml package. The new selenium grid architecture now uses toml file instead of json file to create node configurations. More info about this here
  • src/start-selenium-node.sh: this new file added contains the logic to start a new selenium grid node docker using the selenium 4 architecture. This file is basically taken directly from the SeleniumHQ/docker-selenium repo using the same approach from this file to create and connect new docker nodes to selenium hub. To read more about this code logic and how it works you can take a look at this folder
  • docker-compose-grid-4.yml: this new docker-compose file is added as a reference or as an example of how to use docker-android with selenium grid using the latest selenium hub architecture and the use of the new environment variables.

Environment Variables:

  • CONNECT_TO_GRID_4: new (optional) environment variable to differentiate grid connections with selenium 4 (new architecture) from selenium 3 or below (old architecture).
  • SE_EVENT_BUS_HOST, SE_EVENT_BUS_PUBLISH_PORT, and SE_EVENT_BUS_SUBSCRIBE_PORT are for registering node docker through the Event Bus defined in Selenium 4. The explanation of this process is here in the official documentation of the SeleniumHQ/docker-selenium repo. Note: Since these variables are always set with the same value, maybe we can just remove them so the user doesn’t have to take care of those values.

Screenshot 2023-01-03 at 9 54 00 PM

Types of changes

Put an x in the boxes that apply

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

These changes were locally tested on a Mac OSx machine.

@esaari
Copy link
Copy Markdown

esaari commented Feb 22, 2023

@LerryAlexander Thanks so much for this PR, this will allow us to use Docker Selenium without having to configure a relay node in Docker. This is something my team is eagerly awaiting. Is there any sort of timeline for moving this forward?

cc @budtmo

@LerryAlexander
Copy link
Copy Markdown
Contributor Author

@LerryAlexander Thanks so much for this PR, this will allow us to use Docker Selenium without having to configure a relay node in Docker. This is something my team is eagerly awaiting. Is there any sort of timeline for moving this forward?

cc @budtmo

Hi @esaari, thank you so much for your feedback on this PR, I'm willing to retake this feature and merge these changes into the master branch, but first I was hoping to have some feedback from @budtmo and maybe tackle the failed checks.

Copy link
Copy Markdown
Owner

@budtmo budtmo left a comment

Choose a reason for hiding this comment

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

Hi @LerryAlexander ,

sorry for late response because I am still working on the whole restructuring for this project like I did on appium-docker-android to make it more readable and easier to maintain.

I have already commented few things so you can have a look and also you need to fix the failing test first, it seems the toml is missing and you can add it here.

To be honest, I dont use Selenium for long time so I dont know how it works with Selenium 4, but I dont really like installing jar file inside the project. does it need to be inside the same container?

let me know if you need any support from me.

src/app.py Outdated
Get the latest selenium server jar url
"""
# Command to find jar url
command = 'curl -sk https://github.com/SeleniumHQ/selenium/releases/ | grep ".jar" | head -n 1 | grep -Eo "/[a-zA-Z0-9./?=_%:-]*"'
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I dont know why we need to install selenium.jar? is it like client to be able to connect to selenium hub? it need to be in the same container or it can be in different container?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

we always need to install specific version instead of installing the latest.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Downloading selenium jar file not work if jar file not in visible part of assets. So as wrote @budtmo need set version
image

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.

Thank you @budtmo @SHELA, yes, you are both right, by the time I created the code to download the jar file those assets had included the .jar extension, but now it was changed to .zip extensions. I will be refactoring this downloading process and set to one specific 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.

I dont know why we need to install selenium.jar? is it like client to be able to connect to selenium hub? it need to be in the same container or it can be in different container?

Yes, in selenium 4 version things changed a bit. We definitely need the jar file to create the connection between the hub and the node as it is specified here at the appium conference - Selenium Grid 4 and Appium together in harmony
Screen Shot 2023-03-02 at 20 07 19

Also, is worth mentioning that I'm using the same approach to create this connection using this code as a reference from the official docker-selenium repository . But I'm open to suggestions or improvements on this, please let me know if it makes sense to you, otherwise, we could try to come up with another solution.

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.

My PR? I got lost 😄

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

hahaha.. :D sorry, I meant @LerryAlexander might create a PR to that docker-selenium and it will be reviewed by you @diemol

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.

Sorry @budtmo I'm lost here. I believe we still need the script proposed in this PR, or maybe I didn’t get you clearly enough. So, when the user is using docker-android image and wants to connect to selenium hub using selenium grid, from the docker-android image I was proposing to use the env variable CONNECT_TO_GRID_4 to run all the script proposed in the PR; so now that script should be moved to docker-selenium repo? Sorry, I'm not getting the logic here, help me to clarify the next steps.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@LerryAlexander if I understand correctly based on the documentation: to be able to connect to Selenium 4.x, you just need to run selenium.jar with .toml file that contains Appium url and because we just need selenium.jar and .toml file, we can create a small Dockerfile in docker-selenium project. it means, we dont need anything to be done here, or do you mean something else? or maybe I miss something?

Copy link
Copy Markdown
Contributor Author

@LerryAlexander LerryAlexander Mar 10, 2023

Choose a reason for hiding this comment

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

Hello, sorry for the late reply @budtmo. Yes, you are right, but the whole idea of this PR was using the docker-android image to be able to create the selenium grid architecture just like the way you mentioned in your docker-compose file exampe but this time using Selenium 4.x, because right now the current script you have src/app.py works using the old architecture. So, I know that the approach of downloading the .jar file is a requisite to connect no Selenium 4.x, but besides having the toml file, so, for example, we need to get the platformVersion or the browserName from the environment variables provided to the docker-android image to inject in the configs section info as you can see in the toml file below:

[node]
detect-drivers = false

[relay]
# Default Appium/Cloud server endpoint
url = "http://localhost:4723/wd/hub"
status-endpoint = "/status"
# Stereotypes supported by the service. The initial number is "max-sessions", and will allocate 
# that many test slots to that particular configuration
configs = [
  "5", "{\"browserName\": \"chrome\", \"platformName\": \"android\", \"appium:platformVersion\": \"11\"}"
]

So, all this connection is happening in android-docker image, it's just that we are updating the image to connect now to Selenium 4.x instead of the old Selenium 3.x architecture, so I don’t see how creating an image in docker-selenium could help us to use this whole approach, do you get my point?
I mean, I can create the docker image in selenium repo that does the thing about downloading the selenium.jar file and the toml configuration, but how can we relate that using the docker android image which set up the emulator inside the container? Maybe I'm missing something, can you explain to me how can we use docker-android with selenium 4.x if we move this whole logic to a Dockerfile in docker-selenium project?

@LerryAlexander
Copy link
Copy Markdown
Contributor Author

LerryAlexander commented Feb 27, 2023

Hi @LerryAlexander ,

sorry for late response because I am still working on the whole restructuring for this project like I did on appium-docker-android to make it more readable and easier to maintain.

I have already commented few things so you can have a look and also you need to fix the failing test first, it seems the toml is missing and you can add it here.

To be honest, I dont use Selenium for long time so I dont know how it works with Selenium 4, but I dont really like installing jar file inside the project. does it need to be inside the same container?

let me know if you need any support from me.

Hi @budtmo ,

Thank you so much for your comments and feedback, they mostly make a lot of sense to me as well. I'm going to get back to you for any support or questions. I will be working on this in the following days.

Thanks in advance!

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 3, 2023

Codecov Report

Merging #338 (b722286) into master (abcdf3f) will decrease coverage by 14.95%.
The diff coverage is 50.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@             Coverage Diff             @@
##           master     #338       +/-   ##
===========================================
- Coverage   70.39%   55.44%   -14.95%     
===========================================
  Files           2        2               
  Lines         152      202       +50     
===========================================
+ Hits          107      112        +5     
- Misses         45       90       +45     
Impacted Files Coverage Δ
src/app.py 54.31% <50.00%> (-15.08%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

device_name = os.getenv('DEVICE', 'chrome')
browser_name = default_web_browser if mobile_web_test else device_name
create_node_config_selenium_grid_4(browser_name, appium_host, appium_port, plafform_name)
download_selenium_server_url = 'https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.7.0/selenium-server-4.7.1.jar'
Copy link
Copy Markdown
Contributor Author

@LerryAlexander LerryAlexander Mar 3, 2023

Choose a reason for hiding this comment

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

@budtmo @SHELA , I set it to version 4.7.1 since is the latest release that has the jar file from these assets at https://github.com/SeleniumHQ/selenium/releases/
Screen Shot 2023-03-02 at 21 52 04

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@LerryAlexander I see there's a selenium-server-4.8.1.jar available: https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.8.0/selenium-server-4.8.1.jar

Just need to expand the full Assets list under the latest release to see it: https://github.com/SeleniumHQ/selenium/releases/tag/selenium-4.8.0

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.

Thank you @esaari .
Yeap, you are right, but the version here is not the major concern, on the discussion above with @budtmo we are trying to figure out a way to avoid downloading the jar file into the container and instead use some kind of an URL to access one fixed jar version.

Comment on lines +32 to +37
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar node \
--publish-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_PUBLISH_PORT} \
--subscribe-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_SUBSCRIBE_PORT} \
--detect-drivers false \
--config /opt/bin/config.toml \
${SE_GRID_URL} ${SE_OPTS}
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.

@budtmo here is where it's required to use the selenium-server.jar in order to make the connection between the hub and the node

coverage==4.2
mock==2.0.0
nose==1.3.7
toml
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Seems that not working. Module not found

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/src/app.py", line 9, in <module>
    import toml
ModuleNotFoundError: No module named 'toml'

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.

@SHELA I don't understand, where did you see this error? Did you run pip install -r requirements.txt first?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@LerryAlexander inside docker error in log: /var/log/supervisor/docker-android.stderr.log
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/root/src/app.py", line 9, in
import toml

@budtmo
Copy link
Copy Markdown
Owner

budtmo commented Mar 7, 2023

@LerryAlexander I am just curious about Selenium Hub integrated with Appium.

how stable the Selenium 4.0 that are connected to Appium Server (compared with Selenium 3.x)? I have tried with Selenium 3.x long time ago and it is not stable at all and thats why I dont use Selenium Hub anymore and I created my own hub privately to replace it.

@LerryAlexander
Copy link
Copy Markdown
Contributor Author

@LerryAlexander I am just curious about Selenium Hub integrated with Appium.

how stable the Selenium 4.0 that are connected to Appium Server (compared with Selenium 3.x)? I have tried with Selenium 3.x long time ago and it is not stable at all and thats why I dont use Selenium Hub anymore and I created my own hub privately to replace it.

That's a good question @budtmo, I have used selenium 3.x in the past, and works fine but I've seen some instability as well. To be honest, I've used Selenium grid 4.x only for creating this PR, and seems to be more stable, it would be fair to maybe give it a chance to Selenium 4.x

@budtmo budtmo closed this Mar 8, 2023
@esaari
Copy link
Copy Markdown

esaari commented Mar 16, 2023

@budtmo I have used Selenium 4 Grid extensively and it's quite a bit better than Selenium 3. One big compelling feature of Selenium Grid 4 is that devtool protocol is supported, so that gives us the ability to do things like throttling, network request interception, etc.

Is it possible we could reopen this PR and allow @LerryAlexander to continue his work? I think quite a few people are eagerly anticipating this feature.

@budtmo
Copy link
Copy Markdown
Owner

budtmo commented Mar 22, 2023

have already discussed with @LerryAlexander privately and it is the best way to do this "custom selenium node" in docker-selenium project to get better update and maintenance activity as it include downloading selenium.jar file and the custom node could probably used for other type of node (not just for Appium) in the future. Lerry is a bit busy so it might take time but feel free if you want to help with the implementation in docker-selenium project @esaari

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.

6 participants