Can't run Lightning Testing Service (LTS) for Salesforce

276 views Asked by At

I have been using SFDX to automate Salesforce development for a little while now with Teamcity. SFDX doesn't always provide the best error messages but the documentation is usually very helpful. Well, or so I thought, until I started working with LTS. Here's the documentation to install LTS - https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/lightning_testing_install.htm. I have read the docs and followed the instructions but I cannot get LTS to work for me. I am able to create a scratch org, and install LTS but I am not able to run the tests.

sfdx force:lightning:test:run -a jasmineTests.app The following command allows you to run the sample Jasmin test. Whenever I try that command I get the following error: ERROR running force:lightning:test:run: Unable to connect to selenium. In the documentation, it doesn't specify the server requiring selenium.

Although the docs don't mention anything about selenium, I have tried downloading selenium-standalone-chrome. I tried running selenium/standalone-chrome as a docker container. But it doesn't work.

Links tried: https://github.com/forcedotcom/LightningTestingService/issues/46 https://github.com/forcedotcom/LightningTestingService/issues/46#issuecomment-457829523 https://github.com/forcedotcom/LightningTestingService/issues/46#issuecomment-347928851

Please help, I have tried almost everything.

2

There are 2 answers

0
mohifleur On BEST ANSWER

Updating the answer in case anyone ever runs into this issue... I got it to work! It turns out that the link I shared above was helpful after all LINK: https://github.com/forcedotcom/LightningTestingService/issues/46

  1. I had to add a variable SELENIUM_REMOTE_URL=http://selenium:4444/wd/hub/ to TeamCity
  2. And create a docker-compose.yml to start up selenium/standalone-chrome:latest
version: "3"
services:
  selenium:
    image: selenium/standalone-chrome:latest
    ports:
      - "4444:4444"
4
David Reed On

You do need Selenium and its associated dependencies (browsers, etc) available in your container environment. Unfortunately, I don't believe any official images or dependency lists are available (and of course, the specific package names will vary by distro). I can tell you that I've had success using the circleci/openjdk:latest-node-browsers image to execute LTS tests in continuous integration.

I have a repository of Salesforce CI examples on GitHub, one of which is a working demo of LTS testing. In abbreviated form, it goes like this.

version: 2
jobs:
  build:
    docker:
        - image: circleci/openjdk:latest-node-browsers
    steps:
        - checkout
        - restore_cache:
            keys:
                - sfdx
        - run:
            name: Install Salesforce DX
            command: |
                if [ ! -d node_modules/sfdx-cli ]; then
                    export SFDX_AUTOUPDATE_DISABLE=true
                    export SFDX_USE_GENERIC_UNIX_KEYCHAIN=true
                    export SFDX_DOMAIN_RETRY=300
                    npm install sfdx-cli
                    node_modules/sfdx-cli/bin/run --version
                    node_modules/sfdx-cli/bin/run plugins --core
                fi
        - save_cache:
            key: sfdx
            paths: 
                - node_modules
        - run: 
            name: Create Scratch Org
            command: |
                openssl aes-256-cbc -k $KEY -in assets/server.key.enc -out assets/server.key -d -md md5
                node_modules/sfdx-cli/bin/run force:auth:jwt:grant --clientid $CONSUMERKEY --jwtkeyfile assets/server.key --username $USERNAME --setdefaultdevhubusername -a DevHub
                node_modules/sfdx-cli/bin/run force:org:create -v DevHub -s -f config/project-scratch-def.json -a scratch
        - run:
            name: Remove Server Key
            when: always
            command: |
                rm assets/server.key
        - run:
            name: Install Lightning Testing Service
            command: |
                node_modules/sfdx-cli/bin/run force:lightning:test:install -t jasmine
        - run: 
            name: Push Source
            command: |
                node_modules/sfdx-cli/bin/run force:source:push -u scratch
        - run:
            name: Run Lightning Tests
            command: | 
                mkdir ~/tests/lightning
                node_modules/sfdx-cli/bin/run force:lightning:test:run -d ~/tests/lightning -r human -a lightningTests.app -o