Download and install selenium, webdriver and chromedriver in DevOps pipelines?

2k Views Asked by At

I am stuck in how to execute Selenium test by CI/CD pipeline. My selenium python-script is in a VM in Azure. I want to run it via CI/CD pipelines. This is what I did:

Downloaded the Artifacts from a build (to get my selenium python-script): enter image description here

Then I moved the selenium python-script login.py to : D:\a\1\a\LoginTestSuite\selenium\bin enter image description here

Then I installed selenium-webdriver (npm install selenium-webdriver) and chromedriver (npm install chromedriver) in D:\a\1\a\LoginTestSuite\selenium\bin enter image description here

enter image description here

so I run the script: enter image description here

But I am getting: from selenium import webdriver ModuleNotFoundError: No module named 'selenium' What I am doing wrong? The installation or the way how I am doing this?

Any help is very appreciate it.

EDIT:

After installing webdriver_manager and running the script:

enter image description here

2

There are 2 best solutions below

1
On BEST ANSWER

you can also use it through webdriver manager, check the chrome version by going to about in chrome and specify the version of compatible chromedriver as version argument

Install manager:

pip install webdriver_manager

Use with Chrome:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager(version="87.0.4280.88").install())
driver.get("https://www.google.com")

uPDATE:

If using chromium chrome:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.utils import ChromeType

driver = webdriver.Chrome(ChromeDriverManager(version="87.0.4280.88",chrome_type=ChromeType.CHROMIUM).install())
driver.get("https://www.google.com")
0
On

Another great suggestion is to use package called chromedriver_autoinstaller. Sometimes after auto-update of chrome you can have trouble to write version of chrome. If you running script on regular basis. it is one of the best way which will automatically take drivers according to your current chrome.

from selenium import webdriver
import chromedriver_autoinstaller

chromedriver_autoinstaller.install()

#maximize the chrome
chrome_options = Options()
chrome_options.add_argument("--start-maximized")

driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.google.com")

you can defiantly remove chrome_options or add more arguments.

Please see the documentation, https://pypi.org/project/chromedriver-autoinstaller/