0

I created a selenium cucumber framework that has a test.

The test needs to open chromeDriver, and it is working when I run it in my IDE without any problems.

When I run the project in Jenkins, although the test runs, the chromeDriver doesn't open at all. The console log is:

17:32:14 Starting ChromeDriver 89.0.4389.23 (61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389@{#294}) on port 4816

17:32:14 Only local connections are allowed.

17:32:14 Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.

17:32:14 ChromeDriver was started successfully.

Of course, this log is shown in my ide with the difference that chromeDriver opens in IDE mode and doesn't open in Jenkins mode.

What can I do?

rezza72
  • 127
  • 1
  • 11
  • Please, provide more description, like: what language do you use? how start driver in your code? do you use local driver or remote one?grid or selenoid? do you use --headless mode on jenkins? does jenkins have Xs for running browser? – Ilya Oblomo Mar 14 '21 at 16:30

2 Answers2

0

First of all you should add more description, like:

  1. what language do you use?
  2. how start driver in your code?
  3. do you use local driver or remote one?grid or selenoid?
  4. do you use --headless mode on jenkins?
  5. does jenkins have Xs for running browser?

There's bunch of solving, but each of them is based on more particular description: Best way, but a bit tricky/expensive:

  1. launch own Grid/Seleloid server on ec2 instance on any cloud platform you like: GCP, AWS, Azure, DigitalOcean etc

  2. install docker and launch selenoid intance

  3. launch selenoid application by downloading from github release page:

    chmod +x cm

    ./cm selenoid start --vnc

  4. get its IP and provide it to your driver creation command

  5. which looks like that:

java:

WebDriver driver = new RemoteWebDriver(new URL(SelenoidIP/wd/hub), firefoxOptions);
driver.get("http://www.google.com");
driver.quit();

ruby:

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :remote, url: SelenoidIP/wd/hub
driver.get "http://www.google.com"
driver.close

python:

from selenium import webdriver

driver = webdriver.Remote(
    command_executor=SelenoidIP/wd/hub)
driver.get("http://www.google.com")
driver.quit() 
Ilya Oblomo
  • 104
  • 4
  • 1
    @GajJulije I get an error on trying to write a comment: `You must have 50 reputation to comment` – Ilya Oblomo Mar 14 '21 at 16:01
  • Yes you need some reputation for that. – Gaj Julije Mar 14 '21 at 16:02
  • @GajJulije better? – Ilya Oblomo Mar 14 '21 at 16:16
  • Yes it is better.Now, you have option to comment. – Gaj Julije Mar 14 '21 at 16:27
  • @GajJulije thank you a lot for your votes! but I changed my answer, don't you think it's poor?I delete it – Ilya Oblomo Mar 14 '21 at 16:28
  • Usualy, you ask person to add the more info into the question, in comments, and after you get the infos , the you post the answer. But it is ok. – Gaj Julije Mar 14 '21 at 16:30
  • 1
    @GajJulije anyway thanks a lot your votes, you made my day! – Ilya Oblomo Mar 14 '21 at 16:31
  • Thanks for your replying. Since I'm new in selenium, so I preferred to ask the main question first, and then give you any required information. Now there is no reason to ask to delete the question if you have come to the conclusion that the information in the main question is poor!! 1- I use java language. 2- I start the driver in this way: `WebDriver driver = new ChromeDriver();` `driver.manage().deleteAllCookies();` `driver.get("http://www.google.com");` `driver.quit();` 3- I use local server 4&5- I don't know anything about --headless and Xs in Jenkins – rezza72 Mar 14 '21 at 16:55
  • Do I have to use docker or selenoid for solving the problem, So anyone who wants to open chromeDriver through Jenkins should use these? I use [this](https://www.udemy.com/course/cucumber-bdd-selenium-java-complete-automation-course/) tutorial and in this tutorial, he didn't use any of what you said. – rezza72 Mar 14 '21 at 16:56
  • @rezza.gholipour no, if you use local jenkins and local webdriver, you shouln't worry about it at all). basically, jenkins is remote server, without UI that's why I should be known about. So, you're running it locally, great, what is your error? – Ilya Oblomo Mar 14 '21 at 17:00
  • There isn't any error. but the chromeDriver doesn't open and I can't see what happened in the testing process. – rezza72 Mar 14 '21 at 17:02
  • @rezza.gholipour try to use that webdriver manager maven dependency, it allows you should worry about chrome driver at all: https://github.com/bonigarcia/webdrivermanager and when you run it jenkins, jenkins install it as well – Ilya Oblomo Mar 14 '21 at 17:11
  • I added webdriver manager dependency and used that in my test class. The test doesn't work when I run the test in IDE. I face this error in the console: `java.lang.IllegalStateException: The path to the driver executable The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html at org.openqa.selenium.internal.Require$StateChecker.nonNull(Require.java:280) ` – rezza72 Mar 15 '21 at 08:37
  • [this](https://justpaste.it/5gh9b) is my test file. – rezza72 Mar 15 '21 at 08:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/229933/discussion-between-ilya-oblomo-and-rezza-gholipour). – Ilya Oblomo Mar 15 '21 at 12:32
0

Update: I found a better solution. Start Jenkins as a process from command line, not as a service, to get Chrome to open.

https://stackoverflow.com/a/41457823/1691651 command line commands:

Jenkins.exe stop
java -jar Jenkins.war

To save your Jenkins configurations, create an Environment Variable for JENKINS_HOME that points to location listed on the "Configure Jenkins" setting.

Old answer:


This also happened to me in webdriver.io when using the "chromedriver" service. To solve it, I had to manually download the chromedriver at https://chromedriver.chromium.org/downloads and then run it via a terminal--I don't know why that fixed it. I don't need to run chromedriver separately in a terminal when testing via command line on the same EC2 instance.

JohnP2
  • 1,899
  • 19
  • 17