From 66394b359fea84bf3e3ede7d89e1b5fb16d33b8b Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 14 Apr 2024 11:56:43 -0400 Subject: [PATCH 1/4] Update the Docker integration --- Dockerfile | 85 +++++++++---------- integrations/docker/ReadMe.md | 47 +++------- integrations/docker/docker_config.cfg | 3 - .../docker/run_docker_test_in_firefox.sh | 6 -- 4 files changed, 56 insertions(+), 85 deletions(-) delete mode 100644 integrations/docker/docker_config.cfg delete mode 100755 integrations/docker/run_docker_test_in_firefox.sh diff --git a/Dockerfile b/Dockerfile index eed272d62c0..ed4893af77b 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,31 @@ # SeleniumBase Docker Image -FROM ubuntu:18.04 +FROM ubuntu:22.04 -#======================================= -# Install Python and Basic Python Tools -#======================================= -RUN apt-get -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false update -RUN apt-get install -y python3 python3-pip python3-setuptools python3-dev python-distribute -RUN alias python=python3 -RUN echo "alias python=python3" >> ~/.bashrc +#============================ +# Install Linux Dependencies +#============================ +RUN apt-get update && apt-get install -y \ + fonts-liberation \ + libasound2 \ + libatk-bridge2.0-0 \ + libatk1.0-0 \ + libatspi2.0-0 \ + libcups2 \ + libdbus-1-3 \ + libdrm2 \ + libgbm1 \ + libgtk-3-0 \ + libnspr4 \ + libnss3 \ + libwayland-client0 \ + libxcomposite1 \ + libxdamage1 \ + libxfixes3 \ + libxkbcommon0 \ + libxrandr2 \ + xdg-utils \ + libu2f-udev \ + libvulkan1 #================================= # Install Bash Command Line Tools @@ -17,8 +35,6 @@ RUN apt-get -qy --no-install-recommends install \ unzip \ wget \ curl \ - libxi6 \ - libgconf-2-4 \ vim \ xvfb \ && rm -rf /var/lib/apt/lists/* @@ -26,24 +42,17 @@ RUN apt-get -qy --no-install-recommends install \ #================ # Install Chrome #================ -RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ - echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \ - apt-get -yqq update && \ - apt-get -yqq install google-chrome-stable && \ - rm -rf /var/lib/apt/lists/* +RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb +RUN apt-get install -y ./google-chrome-stable_current_amd64.deb +RUN rm google-chrome-stable_current_amd64.deb -#================= -# Install Firefox -#================= -RUN apt-get -qy --no-install-recommends install \ - $(apt-cache depends firefox | grep Depends | sed "s/.*ends:\ //" | tr '\n' ' ') \ - && rm -rf /var/lib/apt/lists/* \ - && cd /tmp \ - && wget --no-check-certificate -O firefox-esr.tar.bz2 \ - 'https://download.mozilla.org/?product=firefox-esr-latest&os=linux64&lang=en-US' \ - && tar -xjf firefox-esr.tar.bz2 -C /opt/ \ - && ln -s /opt/firefox/firefox /usr/bin/firefox \ - && rm -f /tmp/firefox-esr.tar.bz2 +#======================================= +# Install Python and Basic Python Tools +#======================================= +RUN apt-get -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false update +RUN apt-get install -y python3 python3-pip python3-setuptools python3-dev python-distribute +RUN alias python=python3 +RUN echo "alias python=python3" >> ~/.bashrc #=========================== # Configure Virtual Display @@ -58,9 +67,9 @@ RUN exec "$@" # Update Python Version #======================= RUN apt-get update -y -RUN apt-get -qy --no-install-recommends install python3.8 +RUN apt-get -qy --no-install-recommends install python3.10 RUN rm /usr/bin/python3 -RUN ln -s python3.8 /usr/bin/python3 +RUN ln -s python3.10 /usr/bin/python3 #============================================= # Allow Special Characters in Python Programs @@ -78,30 +87,20 @@ COPY integrations /SeleniumBase/integrations/ COPY requirements.txt /SeleniumBase/requirements.txt COPY setup.py /SeleniumBase/setup.py RUN find . -name '*.pyc' -delete -RUN find . -name __pycache__ -delete RUN pip3 install --upgrade pip setuptools wheel RUN cd /SeleniumBase && ls && pip3 install -r requirements.txt --upgrade RUN cd /SeleniumBase && pip3 install . -#===================== -# Download WebDrivers -#===================== -RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz -RUN tar -xvzf geckodriver-v0.34.0-linux64.tar.gz -RUN chmod +x geckodriver -RUN mv geckodriver /usr/local/bin/ -RUN wget https://chromedriver.storage.googleapis.com/72.0.3626.69/chromedriver_linux64.zip -RUN unzip chromedriver_linux64.zip -RUN chmod +x chromedriver -RUN mv chromedriver /usr/local/bin/ +#======================= +# Download chromedriver +#======================= +RUN sbase get chromedriver --path #========================================== # Create entrypoint and grab example tests #========================================== COPY integrations/docker/docker-entrypoint.sh / -COPY integrations/docker/run_docker_test_in_firefox.sh / COPY integrations/docker/run_docker_test_in_chrome.sh / RUN chmod +x *.sh -COPY integrations/docker/docker_config.cfg /SeleniumBase/examples/ ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["/bin/bash"] diff --git a/integrations/docker/ReadMe.md b/integrations/docker/ReadMe.md index 6bcbabed7eb..455be9b4b70 100644 --- a/integrations/docker/ReadMe.md +++ b/integrations/docker/ReadMe.md @@ -1,56 +1,42 @@ ## Docker setup instructions for SeleniumBase -#### 1. Install the Docker Toolbox: +#### 1. Install the Docker Desktop: You can get that from here: -https://www.docker.com/products/docker-toolbox +https://www.docker.com/products/docker-desktop/ You might also want to install the Docker Engine: -https://docs.docker.com/engine/installation/ +https://docs.docker.com/engine/install/ -#### 2. Create your SeleniumBase Docker environment: +#### 2. Go to the SeleniumBase home directory on the command line, which is where [Dockerfile](https://github.com/seleniumbase/SeleniumBase/blob/master/Dockerfile) is located. (This assumes you've already cloned the SeleniumBase repo.) - docker-machine create --driver virtualbox seleniumbase - -##### (If your Docker environment ever goes down for any reason, you can bring it back up with a restart.) - - docker-machine restart seleniumbase - -#### 3. Configure your shell: - - eval "$(docker-machine env seleniumbase)" - -#### 4. Go to the SeleniumBase home directory on the command line, which is where [Dockerfile](https://github.com/seleniumbase/SeleniumBase/blob/master/Dockerfile) is located. (This assumes you've already cloned the SeleniumBase repo.) - -#### 5. Create your Docker image from your Dockerfile: (Get ready to wait awhile) +#### 3. Create your Docker image from your Dockerfile: (Get ready to wait awhile) docker build -t seleniumbase . -If running on an Apple M1 Mac, use this instead: +If running on an Apple M1/M2 Mac, use this instead: docker build --platform linux/amd64 -t seleniumbase . -#### 6. Run [the example test](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) with Chrome inside your Docker: (Once the test completes after a few seconds, you'll automatically exit the Docker shell) +M1/M2 Mac users should also see [StackOverflow.com/a/76586216/7058266](https://stackoverflow.com/a/76586216/7058266) to **Enable Rosetta in Docker Desktop**. (Otherwise **you will** encounter errors like this when Chrome tries to launch: `"Chrome failed to start: crashed."`) - docker run seleniumbase ./run_docker_test_in_chrome.sh - -#### 7. Now run the same test with Firefox inside your Docker: +#### 4. Run [the example test](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) with Chrome inside your Docker: (Once the test completes after a few seconds, you'll automatically exit the Docker shell) - docker run seleniumbase ./run_docker_test_in_firefox.sh + docker run seleniumbase ./run_docker_test_in_chrome.sh -#### 8. You can also enter Docker and stay inside the shell: +#### 5. You can also enter Docker and stay inside the shell: docker run -i -t seleniumbase -#### 9. Now you can run the example test from inside the Docker shell: +#### 6. Now you can run the example test from inside the Docker shell: ./run_docker_test_in_chrome.sh -#### 10. When you're satisfied, you may exit the Docker shell: +#### 7. When you're satisfied, you may exit the Docker shell: exit -#### 11. (Optional) Since Docker images and containers take up a lot of space, you may want to clean up your machine from time to time when they’re not being used: +#### 8. (Optional) Since Docker images and containers take up a lot of space, you may want to clean up your machine from time to time when they’re not being used: Details on that can be found here: http://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers @@ -67,15 +53,10 @@ If you want to completely remove all of your Docker containers and images, use t docker rm -f $(docker ps -a -q) docker rmi -f $(docker images -q) -Finally, if you want to wipe out your SeleniumBase Docker virtualbox, use these commands: - - docker-machine kill seleniumbase - docker-machine rm seleniumbase - For more cleanup commands, check out: https://codefresh.io/blog/everyday-hacks-docker/ -#### 13. (Optional) More reading on Docker can be found here: +#### 9. (Optional) More reading on Docker can be found here: * https://docs.docker.com * https://docs.docker.com/get-started/ * https://docs.docker.com/docker-for-mac/ diff --git a/integrations/docker/docker_config.cfg b/integrations/docker/docker_config.cfg deleted file mode 100644 index 9812ff3f0f4..00000000000 --- a/integrations/docker/docker_config.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[nosetests] -nocapture=1 -logging-level=INFO diff --git a/integrations/docker/run_docker_test_in_firefox.sh b/integrations/docker/run_docker_test_in_firefox.sh deleted file mode 100755 index c0e19a77c1c..00000000000 --- a/integrations/docker/run_docker_test_in_firefox.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e -# Run example test from inside Docker image -echo "Running example SeleniumBase test from Docker with headless Firefox..." -cd /SeleniumBase/examples/ && pytest my_first_test.py --browser=firefox --headless -exec "$@" From 6b84d945e2dda92eaeb93c7c08164fbc6ff3c91c Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 14 Apr 2024 11:57:14 -0400 Subject: [PATCH 2/4] Refresh Python dependencies --- mkdocs_build/requirements.txt | 2 +- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mkdocs_build/requirements.txt b/mkdocs_build/requirements.txt index 4b0523b3b95..7fa648d7e95 100644 --- a/mkdocs_build/requirements.txt +++ b/mkdocs_build/requirements.txt @@ -3,7 +3,7 @@ regex>=2023.12.25 pymdown-extensions>=10.7.1 -pipdeptree>=2.18.0 +pipdeptree>=2.18.1 python-dateutil>=2.8.2 Markdown==3.6 markdown2==2.4.13 diff --git a/requirements.txt b/requirements.txt index 9e6dd59c157..10cecb7d23e 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ pip>=24.0 packaging>=24.0 setuptools>=68.0.0;python_version<"3.8" -setuptools>=69.2.0;python_version>="3.8" +setuptools>=69.5.1;python_version>="3.8" wheel>=0.42.0;python_version<"3.8" wheel>=0.43.0;python_version>="3.8" attrs>=23.2.0 diff --git a/setup.py b/setup.py index 61476ff7734..fabdf8310b3 100755 --- a/setup.py +++ b/setup.py @@ -149,7 +149,7 @@ 'pip>=24.0', 'packaging>=24.0', 'setuptools>=68.0.0;python_version<"3.8"', - 'setuptools>=69.2.0;python_version>="3.8"', + 'setuptools>=69.5.1;python_version>="3.8"', 'wheel>=0.42.0;python_version<"3.8"', 'wheel>=0.43.0;python_version>="3.8"', 'attrs>=23.2.0', From e657a86427707db0d731df1106dfa328597b1081 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 14 Apr 2024 11:58:04 -0400 Subject: [PATCH 3/4] Update examples --- examples/raw_games.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/raw_games.py diff --git a/examples/raw_games.py b/examples/raw_games.py new file mode 100644 index 00000000000..e5684f2ce94 --- /dev/null +++ b/examples/raw_games.py @@ -0,0 +1,16 @@ +"""SB Manager using UC Mode for evading bot-detection.""" +from seleniumbase import SB + +with SB(uc=True, test=True, disable_csp=True) as sb: + url = "https://steamdb.info/" + sb.driver.uc_open_with_reconnect(url, 3) + sb.uc_click("a.header-login span", 4) + if not sb.is_text_visible("Sign in", "button#js-sign-in"): + sb.driver.uc_open_with_reconnect(url, 3) + sb.uc_click("a.header-login span", 4) + sb.assert_text("Sign in", "button#js-sign-in", timeout=3) + sb.driver.uc_click("button#js-sign-in", 2) + sb.highlight("div.page_content form") + sb.highlight('button:contains("Sign in")', scroll=False) + sb.set_messenger_theme(location="top_center") + sb.post_message("SeleniumBase wasn't detected", duration=4) From e864526e7ae47924ba50f95a61d8a621bcee665b Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 14 Apr 2024 11:58:28 -0400 Subject: [PATCH 4/4] Version 4.25.4 --- seleniumbase/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seleniumbase/__version__.py b/seleniumbase/__version__.py index 1f75a215f59..fb3c4f1fa0f 100755 --- a/seleniumbase/__version__.py +++ b/seleniumbase/__version__.py @@ -1,2 +1,2 @@ # seleniumbase package -__version__ = "4.25.3" +__version__ = "4.25.4"