2

When Travis builds my application and comes to Selenium tests, it throws the following message in the log:

Only local connections are allowed.

and then tests fail with org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally exception

.travis.yml:

language: java
jdk:
  - openjdk8
sudo: required
dist: trusty
addons: # get google-chrome-stable
  chrome: stable
before_script:
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
  - sleep 3 
install: 
    - wget -N http://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip -P ~/
    - unzip ~/chromedriver_linux64.zip -d ~/
    - rm ~/chromedriver_linux64.zip
    - sudo mv -f ~/chromedriver /usr/local/share/
    - sudo chmod +x /usr/local/share/chromedriver

and then

System.setProperty("webdriver.chrome.driver", "/usr/local/share/chromedriver");
webDriver = new ChromeDriver();

Dependency

   <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.14.0</version>
    </dependency>

I feel like it's something about Travis configuration. My application is web-based(Spring), so It has to be working in order to be tested. What should I do so that Selenium tests with Chrome driver will be able to work on Travis CI?

So far, I've seen many ways of solving the problem but none of them worked. I feel like it's impossible. Why is this that problematic?

Updated.

An attempt, as @LucasTierney told, to remove - google-chrome-stable --headless --disable-gpu --no-sandbox --remote-debugging-port=80 http://localhost & didn't do any changes.

Updated

Well, finally it began to work with the same config above. I don't know what happend and why it didn't work earlier.

THE Waterfall
  • 645
  • 6
  • 17
  • Have a look at https://stackoverflow.com/questions/38846079/only-local-connections-are-allowed-chrome-selenium-webdriver – Balwinder Singh Nov 09 '18 at 05:34
  • 1
    @BalwinderSingh didn't help. The thing is that I face this issue only when I use Travis but not when I do testing on my local machine – THE Waterfall Nov 09 '18 at 06:49
  • "Only local connections are allowed" is expected – Corey Goldberg Nov 09 '18 at 16:01
  • @CoreyGoldberg what's the issue there? Looks like I did everything as supposed to be – THE Waterfall Nov 09 '18 at 17:58
  • why are you starting a browser in the before_install step? – Corey Goldberg Nov 09 '18 at 20:05
  • @CoreyGoldberg in the **updated** section I said that removed that line but it didn't help – THE Waterfall Nov 10 '18 at 08:05
  • then edit your question and remove it from the code – Corey Goldberg Nov 11 '18 at 12:50
  • why are you installing in /usr/local/share/ and symlinking it? – Corey Goldberg Nov 11 '18 at 12:57
  • @CoreyGoldberg Well, apparently, I was using [this guide](https://www.amihaiemil.com/2017/07/14/selenium-headless-chrome-travis.html) and it was written there to do so. But, as I've tested, If I comment row with symlink and then change `System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");` to `System.setProperty("webdriver.chrome.driver", "/usr/local/share/chromedriver");`, nothing changes. So I don't actually know what the purpose of symlinking there is. – THE Waterfall Nov 11 '18 at 17:15

1 Answers1

0

You are using a chromedriver version that is too old. 2.30 only supports (officially) v58-60. If you're going to use the latest stable (currently 70), as you're installing, you should use a chromedriver that supports it. That would be 2.42 or greater

Lucas Tierney
  • 2,503
  • 15
  • 13
  • My mistake I didn't mention but I already tried to use the newest chromedriver version. Unfortunately, the result was still the same. – THE Waterfall Nov 09 '18 at 13:44
  • Why are you starting the chrome browser before running your tests? This will cause issues ` - google-chrome-stable --headless --disable-gpu --no-sandbox --remote-debugging-port=80 http://localhost &` – Lucas Tierney Nov 09 '18 at 13:46
  • What do you mean? But how would I be able to test without a started browser If Selenium requires browser? – THE Waterfall Nov 09 '18 at 13:51
  • Selenium starts the browser for you, it cannot connect to a browser already running – Lucas Tierney Nov 09 '18 at 13:52
  • Well, I commented this `- google-chrome-stable --headless --disable-gpu --no-sandbox --remote-debugging-port=80 http://localhost &` but the same issue remained – THE Waterfall Nov 09 '18 at 13:57
  • Did you also use 2.42+? – Lucas Tierney Nov 09 '18 at 14:01
  • If you're talking about webdriver, then yes, I did. – THE Waterfall Nov 09 '18 at 14:02
  • Not sure then, we use it every commit in the selenium project. Try this to install chrome instead? https://github.com/SeleniumHQ/selenium/blob/master/.travis.yml#L36-L38 – Lucas Tierney Nov 09 '18 at 14:10
  • There's still the same trouble – THE Waterfall Nov 09 '18 at 14:16
  • If it's possible, can you provide your .travis.yml with minimum needed configuration to work with selenium and chromedriver? – THE Waterfall Nov 11 '18 at 17:45
  • These two files might be easier to read. I don't have time to create a smaller one and test it. https://github.com/watir/nerodia/blob/master/travis.sh https://github.com/watir/nerodia/blob/master/.travis.yml – Lucas Tierney Nov 11 '18 at 18:11
  • Thanks a lot for your impact. I have another issue with running Java webapp on Travis. [Check it out](https://stackoverflow.com/questions/53268198/how-to-make-webapp-run-on-travis-ci) as soon as you have some time if you're aware of doing such things. – THE Waterfall Nov 13 '18 at 09:48