'Deploying a Spring Boot-Selenium app on Heroku or any cloud service platform

I'm currently using Spring Boot App to Build a LineBot backend Server,and intend to deploy this app to Heroku.

Everything is good except when it comes to using Selenium to webcrawl chrome on Heroku.

My current tests result are as follows:

  1. Adding chromdriver.exe in resourece file and selenium in pom.xml, tested locally selenium and chrome worked fine, but after I deploy on Heroku. My app seems can't find the path of the chromeDriver.
        System.getProperties().setProperty("webdriver.chrome.driver",
                "src/test/resources/chromedriver.exe");
  1. So I follow this python-Based tutorial to set my spring boot app on heroku: https://www.andressevilla.com/running-chromedriver-with-python-selenium-on-heroku/ And I changed the chromedriver's path to match heroku's Config Vars, but the result was still the same,app seemed couldn't find the path of the chromeDriver.
        System.getProperties().setProperty("webdriver.chrome.driver",
                System.getenv("CHROMEDRIVER_PATH"));

Below is what app on Heroku's log shows:

remote:        java.lang.IllegalStateException: The driver executable does not exist: /app/.chromedriver/bin/chromedriver
remote:         at linechrordbot.service.selenium.SeleniumTest.testGetGooglePage(SeleniumTest.java:36)

Any help or direction to solve the problem is much appreciate! and if there are other platforms to deploy a backend server with selenium are consider good news to me!

what my overall test code looks like:

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.boot.test.context.SpringBootTest;

import lombok.extern.slf4j.Slf4j;

@SpringBootTest
@Slf4j
public class SeleniumTest {

    @Test
    public void testGetGooglePage() {
        String uri = "http://xxxxxxxxx.......";

        // where to find chromedirver
      //System.getProperties().setProperty("webdriver.chrome.driver",
      //"src/test/resources/chromedriver.exe");
        System.getProperties().setProperty("webdriver.chrome.driver",
                System.getenv("CHROMEDRIVER_PATH"));

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--no-sandbox");
        chromeOptions.addArguments("--disable-dev-shm-usage");
        chromeOptions.addArguments("--headless"); 
        WebDriver webDriver = new ChromeDriver(chromeOptions);

        webDriver.get(uri);
        WebElement webElements = webDriver.findElement(By.id("price9"));
        String stockPrice = webElements.getText();
        log.info("something to show >>> {}", stockPrice);
        webDriver.close();
        assertEquals(1, 1);
    }

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source