Azure pipeline run selenium script - selenium

I have a Selenium automation that I wrote in python to test the workflow of my website.
In my script I set a PATH and a webdriver as follow:
PATH = "<path-to->/ChromeWebDriver/chromedriver"
driver = webdriver.Chrome(PATH)
Goes without saying that this works just fine and without any issue. and I am able to run my script.
Now I wanted to try to integrate this script in a azure DevOps pipeline to automate this script every tot hours.
but I am getting and error (reasonable error) during the pipeline trigger.
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
I understand that the PATH I have declared in my code, it won't work as not different, but how can I configure my pipeline to add the chrome driver to a windows vm during the process?
because I have a yaml file that is configured as follow
trigger:
- master
variables:
vmImageName: 'ubuntu-latest'
steps:
- task: UsePythonVersion#0
inputs:
versionSpec: '3.x'
addToPath: true
- script: |
python -m pip install --upgrade pip
pip install selenium
- task: Pythonscript#0
inputs:
scriptSource: 'filePath'
scriptPath: './test.py'
Is there a way how I can set the path? thank you so so much in advance
EDIT:
I did something different. In my repo I added ubuntu chrome driver and pointed my PATH to that folder. When I run the pipeline in azure, I get this error.
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Problem solved, I have to download chrome driver for ubuntu, change my configuration pipeline to run on a ubuntu vm, and create a folder with the chromedriver where my pipeline was. and deploy everything.

Related

Chromedriver can’t be opened because Apple cannot check it for malicious software

Environment:
OS : Big Sur 11.1
Homebrew 3.2.13
Python 3.9.7
Command:
chromedriver —version
Error GUI Alert:

Error via output of .py file attempt to run chromedriver:
raise WebDriverException(selenium.common.exceptions.WebDriverException: Message: Service /opt/homebrew/bin/chromedriver unexpectedly exited. Status code was: -9
Fix Method (1)
As stated in the alert, try updating chromedriver:
Uninstall the current version:
brew uninstall chromedriver
Verify that chromedriver is uninstalled:
brew info chromedriver
Install the newest version of chromedriver:
brew install chromedriver
You can also try:
brew reinstall chromedriver
Fix Method (2) : Still Stuck
If you are still experiencing the issue, this fix helped me.
Determine which chromedriver is being used, run:
which chromedriver
Result :
/opt/homebrew/bin/chromedriver
Use the path to chromedriver in the following command to unblock it.
xattr -d com.apple.quarantine /opt/homebrew/bin/chromedriver
Now run the following:
chromedriver —version
Result :
ChromeDriver 93.0.4577.63
Chromedriver should successfully execute.
Reference
coorasse's answer.
For downloading from the chrome drive website
this one worked for me for MAC m1 chip
Use the path to chromedriver in the following command to unblock it.
xattr -d com.apple.quarantine path/to/chromedrive
I had the same issue this morning, this is what fixed it for me.
Go to the system and preferences -> security and privacy.
Then under general tab you will see a notification that about the
exec you are trying to open.
Just click "open anyway" there.
Go back to the chromedriver exe and open it it will then give you the same error but along with that you will get an option to open it.
Click Open and it should resolve.
Worked for me.

Selenium chrome PHP webdriver (unknown error: DevToolsActivePort file doesn't exist)

Have a selenium test in docker which suddenly stopped working
In logs it shows
Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownErrorException: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has
crashed.)
I logged into the container and manually installed google-chrome-stable (90.0.4430.85-1) and chromium-chromedriver (90.0.4430.72-0ubuntu0.16.04.1)
When launching Chrome it gives the error
Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
I then launched it with --no-sandbox flag, but now it returns
[264:264:0424/105210.655665:ERROR:browser_main_loop.cc(1386)] Unable to open X display.
root#9a0073021ee5:/usr/bin# [0424/105210.664350:ERROR:nacl_helper_linux.cc(307)] NaCl helper process running without a sandbox!
I tried all of the possible suggested flags like ["no-sandbox", "headless", "disable-gpu", "disable-dev-shm-usage"]
But it doesn't work.
Any help is greatly appreciated
Has nothing to do with Ubuntu that's inside the docker container, issue is somehow related to the Docker Desktop running on windows which starts these containers in the first place. Identical Docker setup but on a linux machine works just fine. Will open another ticket based on this info.

"cannot find Chrome binary error" when running Selenium chrome driver in a Google Cloud instance (on jupyter Lab)

I'm using a Jupyter Lab notebook which run on google cloud instance. After I installed chromedriver using the following command line:
wget https://chromedriver.storage.googleapis.com/85.0.4183.87/chromedriver_linux64.zip
then I unzip it with:
unzip chromedriver_linux64.zip
After which I run the following cell:
from selenium import webdriver
path = '/home/jupyter/chromedriver'
driver = webdriver.Chrome(path)
And this is where I get the error : WebDriverException: Message: unknown error: cannot find Chrome binary (I'm pretty sure the path to Chromedriver is right though)
This work perfectly on my local machine but I'm a bit lost as to why I can't have it work on a Google Cloud instance. Can you please help me out with this issue ? (Also I have tried other things by looking at other posts online but without success). Thank you
Here is an example on how to install Selenium on a Jupyter notebook.
It is recommended to install it wit pip:
!pip install selenium
and to import os and sys:
import os
import sys
os.path.dirname(sys.executable)

Running selenium-chromedriver using Protractor on linux

I am using protractor to run tests against an Angular application. They work on my OSX environment but not on Linux where TeamCity is trying to run it.
When I run this command on my local OSX environment, it works (tested on my co-workers machine, too):
./node_modules/protractor/bin/protractor protractor.conf.js
Using ChromeDriver directly...
..
Finished in 5.55 seconds
2 tests, 2 assertions, 0 failures
When I run this on a linux machine, or a TeamCity job tries to run it, it fails:
./node_modules/protractor/bin/protractor protractor.conf.js
Using ChromeDriver directly...
/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:87
Error('Timed out waiting for the WebDriver server at ' + url));
^
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:52959/
at Error (<anonymous>)
at onResponse (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:87:11)
at /usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:42:21
at /usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/http/http.js:96:5
at ClientRequest.<anonymous> (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:136:7)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:415:13)
==== async task ====
WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:49)
at Function.webdriver.WebDriver.createSession (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:111:30)
Attempts to resolve:
I have looked at this issue, but a standalone webdriver server is no solution.
I looked at this issue but my version of selenium-wedriver is 2.42.1, so, not the same bug.
Versions:
$ node --version
v0.10.26
$ ./node_modules/protractor/bin/protractor --version
Version 1.0.0
$ uname -mrs
Linux 3.11.0-15-generic x86_64
Progress Update:
Trying to get the version of chrome-webdriver exposed a problem:
$ ./node_modules/protractor/selenium/chromedriver --version
./node_modules/protractor/selenium/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
From this I concluded there was a dependency issue and found that Selenium requires Chrome. (more).
I installed Chrome on the Linux box using steps like this:
sudo apt-get install libxss1 libappindicator1 libindicator7
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
This didn't work exactly like that, but after a few back and forths with dependencies and sudo apt-get install I think I got Chrome installed:
$ google-chrome --version
Google Chrome 36.0.1985.143
This made the chromedriver version work:
$ ./node_modules/protractor/selenium/chromedriver --version
ChromeDriver 2.10.267518
However, running Protractor still does not work:
$ ./node_modules/protractor/bin/protractor protractor.conf.js
Using ChromeDriver directly...
/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109
var template = new Error(this.message);
^
UnknownError: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.10.267518,platform=Linux 3.11.0-15-generic x86_64)
at new bot.Error (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
at Object.bot.response.checkResponse (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
You need to be able to run Chrome or Firefox headless and for that you'll need to configure Xvfb among other things, otherwise Chrome will fail to launch without a proper $DISPLAY.
You could also use PhantomJS but, IMHO, what good does that to e2e testing since is not a real browser.
This is what I'm successfully using for continuous testing: https://github.com/elgalu/docker-selenium
I had the same problem and it resolved just after installing unity-gtk3-module !!
yum install unity-gtk3-module
Installing:
PackageKit-gtk3-module
Updating:
Installing for dependencies:
PackageKit-glib
adwaita-cursor-theme
adwaita-icon-theme
at-spi2-atk
at-spi2-core
cairo-gobject
colord-libs
gtk3
json-glib
libXevie
libgusb
rest
Updating for dependencies:
glib2
i hope this helps

chrome not reachable on travis ci

I am trying to use chrome standalone driver on Travis CI server. I am getting this error:
selenium.common.exceptions.WebDriverException: Message: u'chrome not reachable\
The script runs fine locally.
in .travis.yml I have
before_script:
# google chrome standalone driver
- wget http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- sudo mv chromedriver /usr/local/bin
- sudo chmod a+x /usr/local/bin/chromedriver
and in my tests I have
from selenium.webdriver import Chrome
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
Chrome()
and after a delay I get the error message stated above.
I have tried changing the location of the chrome driver, and explicitly pass the executable_path to Chrome, but no joy.
I've successfully run tests in Travis using headless Chrome.
I've used the following arguments to start chrome:
no-sandbox
no-default-browser-check
no-first-run
disable-default-apps
The no-sandbox argument was the one that bypassed the 'chrome not reachable' error.