Bitbucket pipeline not running Chromedriver executable - selenium

So I'm running in to an error where I have a simple front end login test to a website using selenium. When I run the test in the bitbucket pipelines I'm running in to this error
java.lang.IllegalStateException: The driver executable does not exist: /opt/atlassian/pipelines/agent/build\chromedriver.exe
Bitbucket yml file
image: gradle:6.6.0
pipelines:
default:
- parallel:
- step:
name: Build and Test
caches:
- gradle
script:
- gradle build
after-script:
- pipe: atlassian/checkstyle-report:0.2.0
- step:
name: Security Scan
script:
# Run a security scan for sensitive data.
# See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
- pipe: atlassian/git-secrets-scan:0.4.3
Does anyone know what the issue may be ?

I see 2 things:
You are specifying the driver file so the route could be incorrect.
java.lang.IllegalStateException: The driver executable does not exist: /opt/atlassian/pipelines/agent/build\chromedriver.exe
You are using a gradle image
image: gradle:6.6.0
but I don't think that you have a driver/browser in that image.
You will need to add another image with a browser, like this https://hub.docker.com/r/selenium/standalone-chrome, you can find more examples here https://github.com/SeleniumHQ/docker-selenium and add it to your file. Something like this:
image: gradle:6.6.0
pipelines:
default:
- parallel:
- step:
name: Build and Test
caches:
- gradle
services:
- chrome
script:
- gradle build
after-script:
- pipe: atlassian/checkstyle-report:0.2.0
- step:
name: Security Scan
script:
# Run a security scan for sensitive data.
# See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
- pipe: atlassian/git-secrets-scan:0.4.3
definitions:
services:
chrome:
image: selenium/standalone-chrome
You will need to change your code to use a RemoteWebDriver
https://www.selenium.dev/documentation/en/remote_webdriver/remote_webdriver_client/

Related

Bitbucket Pipeline custom variable is not showing its value in step script

I have created a pipeline for running automation script from bitbucket, when I trigger build with docker container all custom variable is working (it pass the correct values) but when I run the same project in self.hosted machine and pass the variables it show blank values.
Below is the sample of pipeline file
# This is an example Starter pipeline configuration
# Use a skeleton to build, test and deploy using manual and parallel steps
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: atlassian/default-image:2
pipelines:
pull-requests: #Trigger pipeline project on each Pull-Request
'**':
- step:
name: 'version check'
image: maven:3.3.9
caches:
- maven
script:
- echo "Your versions here..."
- mvn --version
- step:
name: 'Clean and Build'
script:
- mvn -f TestAutomation/pom.xml clean compile
custom:
Automation-Run: #Name of this pipeline
- variables:
- name: testngFile
default: "src/test/resources/testng"
- name: browser
default: "CHROME"
allowed-values: # optionally restrict variable values
- "CHROME"
- "FIREFOX"
- name: environment
default: STAGING
allowed-values:
- "STAGING"
- "QA"
- "PROD"
- name: forkCount
default: "0"
- name: tags
default: Regression
- step:
name: 'Connect to Runner & Automation-Run'
runs-on:
- self.hosted
- windows
- testautomation
script:
- cd TestAutomation
- .\Example1.bat ${testngFile} ${browser} ${environment} ${tags}
artifacts:
- /target/surefire-reports/**.xml
inside Example1.bat file I have mentioned below command
mvn clean test -Dproject.testngFile=%1 -Dbrowser.name=%2 -Dproject.environment=%3 -Dcucumber.filter.tags=#%4
enter image description here
enter image description here
I am expecting when user enter any values, it picked and stored into variable and those variables are pass to Example1.bat as runtime command line args.

Selenium-JAVA maven project CI/CD pipeline using CircleCI

I tried to create CI/CD pipeline for Selenium maven project using CircleCI. but I found webDriverException. Here, I attached screenshot and circleCI.yml file. enter image description here
enter image description hereenter image description here
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:11-jdk
working_directory: ~/demoProject
environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: mvn dependency:go-offline
- run:
name: Running X virtual framebuffer
command: Xvfb :0 -ac &
- run:
name: Run Tests
command: |
export DISPLAY=:99
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}
# run tests!
- run: mvn clean test
- store_artifacts:
path: target/surefire-reports
destination: tr1
- store_test_results:
path: target/surefire-reports

Cannot run quarkus test on gitlab CI

Everything works on my machine. Problem is when I run tests on gitlab CI i get this error :
AuthenticationResourceTest > signinuser exists => returns a jwt token FAILED
java.lang.RuntimeException at QuarkusTestExtension.java:626
Caused by: java.lang.reflect.InvocationTargetException at NativeMethodAccessorImpl.java:-2
Caused by: java.util.concurrent.CompletionException at CompletableFuture.java:314
Caused by: java.lang.RuntimeException at TestResourceManager.java:457
Caused by: java.lang.IllegalStateException at DockerClientProviderStrategy.java:15
As my project is using Lombok could this be related to it? (but why does it work on my machine???).
Here is my .gitlab-ci:
stages:
- build
- test
build:
stage: build
image: openjdk:16
script: ./gradlew --build-cache quarkusBuild
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
test:
stage: test
image: openjdk:16
script: ./gradlew check
artifacts:
name: coverage
paths:
- $CI_PROJECT_DIR/build/jacoco-report
reports:
junit: jacoco.xml
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
Really struggling here.
Found the error.
Forgot that testcontainer needs docker dind
For those who struggle with this: test containers needs to run a docker container in order to create a test database.
That's the purpose of the dind service (docker in docker).
from
https://www.testcontainers.org/supported_docker_environment/continuous_integration/gitlab_ci/
Here is a sample .gitlab-ci.yml that executes test with gradle:
# DinD service is required for Testcontainers
services:
- name: docker:dind
# explicitly disable tls to avoid docker startup interruption
command: ["--tls=false"]
variables:
# Instruct Testcontainers to use the daemon of DinD.
DOCKER_HOST: "tcp://docker:2375"
# Instruct Docker not to start over TLS.
DOCKER_TLS_CERTDIR: ""
# Improve performance with overlayfs.
DOCKER_DRIVER: overlay2
test:
image: gradle:5.0
stage: test
script: ./gradlew test

docker-compose using cached file with pytest

I've configured IntelliJ to use python via a stack I've defined in docker-compose. I'm configured my project to execute my pytest via docker-compose so that I can use the debugger. However, I've discovered that after the initial run, when I change my code and re-run my tests, pytest is not seeing my changes, but rather executing a cached version of the code.
The only way I've discovered to get around this is to invoke the File menu option Invalidate Caches and Restart. This is annoying.
This my compose file:
networks:
app: {}
services:
item-set-definitions:
build:
context: /Users/kudrykma/ghoildex/kudrykma/analytics/sa-item-set-definitions
target: build
command:
- /bin/bash
image: item-sets:test
networks:
app: {}
volumes:
- source: /Users/kudrykma/ghoildex/kudrykma/analytics/sa-item-set-definitions
target: /project
type: bind
version: '3.9'
In the pytest Run configuration I've tried adding -force-recreate option in the docker-compose Command and options field but IntelliJ won't recognize it.
Does anyone know how I can configure IntelliJ to not cache any of my source file so that pytest will see my changed code?
Thank you

Can't get tests to pass on Gitlab CI

I've been trying to get our tests to pass on our Gitlab CI, but can't. I'm using the stock pipelines config that comes with Gitlab. All I've had to do is provide the gitlab yaml file to config the CI.
This is what we're using
image: maven:3.5.0-jdk-8-alpine
services:
- postgres:latest
variables:
POSTGRES_DB: my_test_db
POSTGRES_USER: my_test_user
POSTGRES_PASSWORD: ""
MAVEN_OPTS: "-Dmaven.repo.local=.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"
ACTIVE_ENV: test
connect:
image: postgres
script:
# official way to provide password to psql: http://www.postgresql.org/docs/9.3/static/libpq-envars.html
- export PGPASSWORD=$POSTGRES_PASSWORD
- psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;"
stages:
- test
test:
stage: test
script:
- "mvn -Denvironments=test -B db-migrator:migrate; mvn -Denvironments=test -DACTIVE_ENV=test -B test"
Everything works perfectly up to the point where the tests run. Then they all error out with similar messages:
383 [main] WARN org.javalite.activeweb.DBSpecHelper - no DB connections are configured, none opened
456 [main] WARN org.javalite.activeweb.DBSpecHelper - no DB connections are configured, none opened
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.528 sec <<< FAILURE! - in app.models.RoleTest
validatePresenceOfUsers(app.models.RoleTest) Time elapsed: 0.071 sec <<< ERROR!
org.javalite.activejdbc.DBException: Failed to retrieve metadata from DB, connection: 'default' is not available
I have one database.properties file that is checked in and is for tests only (our dev and prod envs use jndi). It looks like so:
test.driver=org.postgresql.Driver
test.username=my_test_user
test.password=
test.url=jdbc:postgresql://postgres/edv_test
Again, migrations run using all this exact same config. I just can't figure out why the tests won't run. I understand why it's saying there's no default db, but I don't get why it's not seeing the test settings and configuring that connection as expected.
So you know, the Maven flag environments like this: mvn test -Denvironments=test only works for the DB-Migrator, and not for the tests. Any JavaLite application in a standard running mode or as a test, it will be looking at ACTIVE_ENV. If this is not set, it will assume development. In test mode, it will be looking at database.properties block development.test.xxx=yyy as in http://javalite.io/database_configuration#property-file-configuration.
Think of it as "development" environment, "test" mode.
Additionally, DbConfig is not involved in tests, as database connections in test have a special treatment (rollback transactions), see: http://javalite.io/testing_with_db_connection