0

Currently running my automation from a pipeline please see yaml file below:

 jobs:
  - job: master
    pool:
      vmImage: ubuntu-latest
    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '10.14'
    displayName: 'Install Node.js'
    - script: npm install
    displayName: 'Install TestCafe'
    - script: npm test
    displayName: 'Run Tests'
    - task: PublishTestResults@2
      inputs:
        testResultsFiles: 'report.xml'
        testResultsFormat: 'JUnit'

this works well the problem I have is that I would live to be able to make the URL dynamic based on variables entered into Azure dev ops

The update yaml file is below:

trigger:
- master

    parameters:
      - name: env
        type: string
        default: testing
        values: 
        - testing
        - bdev
        - fdev
    
      - name: person
        type: string
        default: uat
        values: 
        - bs
        - nk
        - uat
        - mc
        - rm
        - pe
        - mv   
        - mm
    
    variables:
        webapp: 'Test-rt5-${{ parameters.env }}-app-${{ parameters.person }}'
        
    Stages:
    - stage: 'Build'
      displayName: 'Build ${{ parameters.env }}-${{ parameters.person }} '
      jobs:
      - job: master
        pool:
          vmImage: ubuntu-latest
        steps:
        - task: NodeTool@0
          inputs:
            versionSpec: '10.14'
        displayName: 'Install Node.js'
        - script: npm install
        displayName: 'Install TestCafe'
        - script: npm test
        displayName: 'Run Tests'
        - task: PublishTestResults@2
          inputs:
            testResultsFiles: 'report.xml'
            testResultsFormat: 'JUnit'

How do I use these variables to form my URL for each test/fixture?

currently using

const URL = 'https://test-rt5-bdev-app-rm.com/';

fixture ("SmokeFuxture")
    .page(URL);
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47

1 Answers1

1

Azure Docs about defining variables state the following:

Notice that variables are also made available to scripts through environment variables.

So, you can use your variable with a dynamically created URL just by accessing the corresponding environment variable in the TestCafe test:

fixture("SmokeFixture")
    .page(process.env.WEBAPP)
wentwrong
  • 711
  • 4
  • 7
  • Thank you, I have now updated my Fixture to the following: fixture ("SmokeFixture") .page(process.env.webapp) The following error is displayed in Dev Ops: > 1 | # Node.js | ^ 2 | # Build a general Node.js project with npm. 3 | # Add steps that analyze code, save build artifacts, deploy, and more: 4 | # https://learn.microsoft.com/azure/devops/pipelines/languages/javascript at Object. (/home/vsts/work/1/s/tests/SmokeTest.js:13:20) – Brandon Short Apr 23 '21 at 09:36
  • Please note that as described in the Azure docs mentioned in the answer above, the name of a variable is upper-cased (use `process.env.WEBAPP`). It's hard to say what is the cause of the error without a full stacktrace/log. However, from the posted error message, I can assume that you put bash comments (lines starting with the '#' symbol) in your JavaScript test and a syntax error occurred. – wentwrong Apr 26 '21 at 08:07