Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serenity BDD Maven Fails on GitLab CI -Timeout, NoSuchElementException, Element not found instead in local machine works #1935

Closed
darken89 opened this issue Jan 29, 2020 · 9 comments
Labels

Comments

@darken89
Copy link

darken89 commented Jan 29, 2020

If I run the maven serenity test in local machine, all works fine. Instead when I run the pipeline on GitLab CI, it fails giving me in the console the following error:

TEST FAILED WITH ERROR: User Authentication
  ---------------------------------------------------------------------
  14:31:46.500 [pool-1-thread-1] DEBUG n.t.c.steps.ConsoleLoggingListener - RELATED ISSUES: 
  14:31:46.646 [pool-1-thread-1] ERROR n.t.c.steps.ConsoleLoggingListener - TEST FAILED AT STEP Perform authentication
  14:31:46.646 [pool-1-thread-1] ERROR n.t.c.steps.ConsoleLoggingListener - Timed out after 50 seconds. Element not found
  Feature: Authentication to the XXXXXXXX
    Scenario Outline: User Authentication # src/test/resources/features/authentication/authentication.feature:3
      Given the "<page>" page
      When I perform authentication as "<role>"
      Then I should be logged in
      Examples: 
    Scenario Outline: User Authentication # src/test/resources/features/authentication/authentication.feature:9
      Given the "login" page             # AuthenticationStepDefinitions.the_page(String)
      When I perform authentication         # AuthenticationStepDefinitions.i_perform_authentication()
        **org.openqa.selenium.NoSuchElementException: Timed out after 50 seconds. Element not found**
  For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
  Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
  System info: host: 'runner-4ZVpZRdnG-project-3-concurrent-0', ip: '172.21.0.7', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-957.1.3.el7.x86_64', java.version: '1.8.0_242'
  Driver info: driver.version: unknown

The configuration that I used is very simple:

this is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>eu.inn.locara</groupId>
	<artifactId>myproject-acceptance-tests</artifactId>
	<version>1.0.0-SNAPSHOT</version>
	<packaging>jar</packaging>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<serenity.version>2.0.69</serenity.version>
		<serenity.maven.version>2.0.69</serenity.maven.version>
		<serenity.cucumber.version>1.0.21</serenity.cucumber.version>
		<cucumber.version>4.2.0</cucumber.version>
		<encoding>UTF-8</encoding>
		<tags></tags>
		<parallel.tests>4</parallel.tests>
		<webdriver.driver>chrome</webdriver.driver>
	</properties>

	<dependencies>
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<version>1.0.13</version>
		</dependency>
		<!-- - To use Cucumber 4, exclude the old Cucumber 2 cucumber-core dependency 
			from the serenity-core dependency - and include the Cucumber 4 cucumber-java 
			and cucumber-junit dependencies. -->
		<dependency>
			<groupId>net.serenity-bdd</groupId>
			<artifactId>serenity-core</artifactId>
			<version>${serenity.version}</version>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>io.cucumber</groupId>
					<artifactId>cucumber-core</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-java</artifactId>
			<version>${cucumber.version}</version>
		</dependency>
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-junit</artifactId>
			<version>${cucumber.version}</version>
		</dependency>
		<dependency>
			<groupId>net.serenity-bdd</groupId>
			<artifactId>serenity-junit</artifactId>
			<version>${serenity.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>net.serenity-bdd</groupId>
			<artifactId>serenity-cucumber4</artifactId>
			<version>${serenity.cucumber.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>eu.mycompany.myproject</groupId>
			<artifactId>myproject-model-dto</artifactId>
			<version>0.0.2-SNAPSHOT</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.22.1</version>
				<configuration>
					<skip>true</skip>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-failsafe-plugin</artifactId>
				<version>2.22.1</version>
				<configuration>
					<includes>
						<include>**/*Test.java</include>
					</includes>
					<systemPropertyVariables>
						<webdriver.driver>${webdriver.driver}</webdriver.driver>
					</systemPropertyVariables>
					<parallel>classes</parallel>
					<threadCount>${parallel.tests}</threadCount>
					<forkCount>${parallel.tests}</forkCount>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>integration-test</goal>
							<goal>verify</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.0</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>net.serenity-bdd.maven.plugins</groupId>
				<artifactId>serenity-maven-plugin</artifactId>
				<version>${serenity.maven.version}</version>
				<configuration>
					<tags>${tags}</tags>
				</configuration>
				<executions>
					<execution>
						<id>serenity-reports</id>
						<phase>post-integration-test</phase>
						<goals>
							<goal>aggregate</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

this is my .gitlab-ci.yml


image: maven:3.6.3-jdk-8
    
variables:
      MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
      MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
    
 stages:
    - test
            
 test:
    stage: test
     allow_failure: true
     services:
         - name: selenium/standalone-chrome     
           alias: selenium
     script:
          - mvn verify

and, finally, this is my serenity.conf:

   webdriver {
      driver = chrome
      use.driver.service.pool = false
      remote.url="http://selenium:4444/wd/hub/"
      remote.driver=chrome
    }
    webdriver.timeouts.implicitlywait=50000
    
    # If open browser or background
    headless.mode = true
    
    #
    # Chrome options can be defined using the chrome.switches property
    #
    chrome.switches="""--window-size=1920,1080;--headless;--start-maximized;--test-type;--no-sandbox;--ignore-certificate-errors;
                       --disable-popup-blocking;--disable-default-apps;--disable-extensions-file-access-check;
                       --incognito;--disable-infobars,--disable-gpu"""
    
    environments {
      default {
    	# used
        webdriver.base.url = "http://gitlabrunner.mycompany.lan/#"
      }
      docker {
    	# not used
        webdriver.base.url = "http://gitlabrunner.mycompany.lan/#"
      }
      dev {
    	# not used
        webdriver.base.url = "https://www.google.it"
      }
      staging {
    	# not used
        webdriver.base.url = "https://www.google.it"
      }
      prod {
    	# not used
        webdriver.base.url = "https://www.google.it"
      }
    }

If i start locally the container selenium/standlone-chrome (see the following image)
image

and I run mvn verify in the console of my local machine (with headless true or false), all works as expected!

Tell me if I missed some important info, so I can add them.
This problem is driving me crazy! Any suggestion is appreciated!

Thanks!

@wakaleo
Copy link
Member

wakaleo commented Jan 29, 2020

If it works locally it’s generally an issue with the test code or the server config. Timings can be different in a headless context.

@darken89
Copy link
Author

Could you tell me in details which server you are talking about? If you talk about the selenium/standlone-chrome is the same container that I run locally. Could you suggest me some test to do troubleshooting?

@wakaleo
Copy link
Member

wakaleo commented Jan 29, 2020

Looking at the screenshots can help. If it just happens on Gitlab maybe it’s more a question for their teams?

@darken89
Copy link
Author

darken89 commented Jan 29, 2020

Thanks for your suggestion @wakaleo , I will post this issue even to the GitLab's team.
Just the last question, is it necessary that the chrome browser is installed in the gitlab runner machine (where is located the maven project) or is it sufficient to use the remote webdriver in the selenium image's (selenium/standlone-chrome)?

@wakaleo
Copy link
Member

wakaleo commented Jan 29, 2020

I think the chrome browser generally needs to be installed, though I may be wrong

@darken89
Copy link
Author

I'm writing just here because in the others forum I don't get any reply yet.

I tried to log in ssh in the machine of the gitlabrunner and trigger manually the mvn verify (without gitlab pipieline) but the issue persists. So the problem isn't of GitLab Runner.

@wakaleo, as u suggest me, I have analyzed the screenshots and, the first step (open page), open a blank page so that selenium cannot find any elements in the page. Do you know the reason for which the page doesn't load correctly? I thought that the problem can depend by the os of the gitlabrunner (linux 3.10.0-957.1.3.el7.x86_64).

@wakaleo
Copy link
Member

wakaleo commented Jan 30, 2020

A blank page is often a driver version issue.

@darken89
Copy link
Author

I thought that the docker image selenium/standalone-chrome was created to solve driver version issues. Isn't that so? I will try to use others tag of the same image (that locally works) to solve the issue.

@wakaleo
Copy link
Member

wakaleo commented Jan 30, 2020

You would need to ask the maintainers of that image.

@wakaleo wakaleo closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants