Forum Discussion

rezza's avatar
rezza
Occasional Contributor
4 years ago

run cucumber selenium tests in gitlab-ci

Hi
I have a selenium cucumber project with some tests.

The tests worked and the chromeDriver had launch when I run the -mvn clean compile test in my IDE.

I created this .gitlab-ci.yml in my project's root:

image: markhobson/maven-chrome:jdk-11

stages:
  - build
  - test

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"


cache:
  paths:
    - .m2/repository/
    - target/

build:
  stage: build
  script:
    - mvn $MAVEN_OPTS clean package
    - mvn compile

test:
  stage: test
  script:
    - mvn test

When I run the pipeline, I face this error in the console:

Unable to load browser: Could not start a new session.
Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.0.0-beta-1', revision: '9c03156c2b'
System info: host: 'runner-fa6cab46-project-25183469-concurrent-0', ip: '172.17.0.4', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.78-coreos', java.version: '11.0.10'
Driver info: org.openqa.selenium.chrome.ChromeDriver

What can I do for running the tests?

  • Hi,

     

    You're gitlab-ci.yml looks good

     

    Can you provide more logs of your pipeline?

    Do you properly run chrome in headless mode?

     

            WebDriverManager.chromedriver().setup();
    
            ChromeOptions options = new ChromeOptions();
            options.setHeadless(true);
    
            driver = new ChromeDriver(options);
    

     

    • rezza's avatar
      rezza
      Occasional Contributor

      aurelien-reeves 
      Hi

      Thanks for replying.

      What is needed to providing?

      May I give all the pipeline's output?

      This is my file which has the driver configurations.

      And This is that file after adding the chromeDriver headLess option.

      As you can see, I added the chromeDriver headLess option.

       

      Before adding, everything is worked in IDE mode.

      But when I add the chromeDriver headLess option, I face this error in the testNG's report:


      feature (Login into account)
      cucumber.runtime.CucumberException: java.lang.AssertionError: Unable to wait and click on the WebElement, using locator: <Proxy element for: DefaultElementLocator 'By.linkText: Sign in'>
      	at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:69)
      	at cucumber.api.testng.AbstractTestNGCucumberTests.feature(AbstractTestNGCucumberTests.java:21)
      Caused by: java.lang.AssertionError: Unable to wait and click on the WebElement, using locator: <Proxy element for: DefaultElementLocator 'By.linkText: Sign in'>
      	at org.junit.Assert.fail(Assert.java:89)
      	at pageObjects.BasePage.waitAndClickElement(BasePage.java:59)
      	at pageObjects.Login_page.clickOnSignInButton(Login_page.java:35)
      	at stepDefinitions.LoginSteps.user_clicks_on_the_login_button_on_homepage(LoginSteps.java:18)
      	at ✽.And User clicks on the login button on homepage(Login.feature:6)
      ... Removed 28 stack frames
      (Runs Cucumber Feature)

       

      I didn't run the test in GitLab mode. because first, I want to solve the problem in IDE mode.

      I'm so new, please guide me.

      Thanks in advanced.

      • For better readability, could you paste your code in the forum using the "insert code sample" snippet instead of JustPaste.it?

         

        And I suggest you run your tests not in headless mode in your IDE. Maybe something is actually failing but as it is in Headless mode, you can not see it.

         

        Can you remove the code about Firefox and IE to make it cleaner and easier to debug?

  • So what is happening here is google chrome is crashing during the run.

     

    Chrome uses /dev/shm for runtime data which is 64MB by default under Docker. If this is not sufficient then this can cause Chrome to crash . Possible workarounds:

    • Increase the size of /dev/shm
    • Mount /dev/shm to the host's
    • Start Chrome with the flag --disable-dev-shm-usage
    •