aws-actions / aws-devicefarm-mobile-device-testing

Run automated Mobile Device Testing on AWS Device Farm
https://docs.aws.amazon.com/devicefarm/latest/developerguide/welcome.html#automated-test-intro
MIT No Attribution
5 stars 1 forks source link

AWS Device Farm Mobile Device Testing for GitHub Actions

Runs a Mobile Device Automated Test on AWS Device Farm.

This GitHub Action allows you to run automated app testing on AWS Device Farm. For example, testing new versions of code being committed to a branch to ensure the App works as desired before proceeding with the next step in the release cycle.

Table of Contents

Input options

Output options

Examples of Usage

Running an Automated Test

Before each of the following examples, make sure to include the following

NOTE:

The value of role-to-assume should be replaced with the AWS IAM Role to be used.

The value of aws-region should be replaced with the AWS Region being used. Please note that AWS Device Farm is currently only available in the us-west-2 region.

For more information on how to configure the configure-aws-credentials action please check here.

      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v2 # More information on this action can be found below in the 'AWS Credentials' section
        with:
          role-to-assume: arn:aws:iam::123456789012:role/my-github-actions-role
          aws-region: us-west-2

Run Device Farm Test and download all artifacts

      - name: Schedule Device Farm Automated Test
        id: run-test
        uses: aws-actions/aws-devicefarm-mobile-device-testing@v2.0
        with:
          run-settings-json: |
            {
              "name": "GitHubAction-${{ github.workflow }}_${{ github.run_id }}_${{ github.run_attempt }}",
              "projectArn": "Test",
              "appArn": "aws-devicefarm-sample-app.apk",
              "devicePoolArn": "Top Devices",
              "test": {
                "type": "APPIUM_NODE",
                "testPackageArn": "MySampleAndroidTests.zip",
                "testSpecArn": "webdriverio_spec_file.yml"
              }
            }
          artifact-types: ALL

      - uses: actions/upload-artifact@v3
        if: always() # This ensures the artifacts are uploaded even if the Test Run Fails
        with:
          name: AutomatedTestOutputFiles
          path: ${{ steps.run-test.outputs.artifact-folder }}

Run Device Farm Test and download only video and screenshot artifacts

      - name: Schedule Device Farm Automated Test
        id: run-test
        uses: aws-actions/aws-devicefarm-mobile-device-testing@v2.0
        with:
          run-settings-json: |
            {
              "name": "GitHubAction-${{ github.workflow }}_${{ github.run_id }}_${{ github.run_attempt }}",
              "projectArn": "Test",
              "appArn": "aws-devicefarm-sample-app.apk",
              "devicePoolArn": "Top Devices",
              "test": {
                "type": "APPIUM_NODE",
                "testPackageArn": "MySampleAndroidTests.zip",
                "testSpecArn": "webdriverio_spec_file.yml"
              }
            }
          artifact-types: VIDEO,SCREENSHOT

      - uses: actions/upload-artifact@v3
        if: always() # This ensures the artifacts are uploaded even if the Test Run Fails
        with:
          name: AutomatedTestOutputFiles
          path: ${{ steps.run-test.outputs.artifact-folder }}

Run Device Farm Test without downloading any artifacts

      - name: Schedule Device Farm Automated Test
        id: run-test
        uses: aws-actions/aws-devicefarm-mobile-device-testing@v2.0
        with:
          run-settings-json: |
            {
              "name": "GitHubAction-${{ github.workflow }}_${{ github.run_id }}_${{ github.run_attempt }}",
              "projectArn": "Test",
              "appArn": "aws-devicefarm-sample-app.apk",
              "devicePoolArn": "Top Devices",
              "test": {
                "type": "APPIUM_NODE",
                "testPackageArn": "MySampleAndroidTests.zip",
                "testSpecArn": "webdriverio_spec_file.yml"
              }
            }

Credentials

AWS Credentials

This action relies on the default behaviour of the AWS SDK for JavaScript to determine AWS credentials and region. Use the aws-actions/configure-aws-credentials action to configure the GitHub Actions environment with a role using GitHub's OIDC provider and your desired region.

NOTE: AWS Device Farm is available in us-west-2 region only. Therefore, it is important to specify us-west-2 as the value of the aws-region property in the configure-aws-credentials step.

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v2
        with:
          role-to-assume: arn:aws:iam::123456789012:role/my-github-actions-role
          aws-region: us-west-2

      - name: Schedule Device Farm Automated Test
        id: run-test
        uses: aws-actions/aws-devicefarm-mobile-device-testing@v2.0
        with:
          run-settings-json: |
            {
              "name": "GitHubAction-${{ github.workflow }}_${{ github.run_id }}_${{ github.run_attempt }}",
              "projectArn": "Test",
              "appArn": "aws-devicefarm-sample-app.apk",
              "devicePoolArn": "Top Devices",
              "test": {
                "type": "APPIUM_NODE",
                "testPackageArn": "MySampleAndroidTests.zip",
                "testSpecArn": "webdriverio_spec_file.yml"
              }
            }

We recommend following Amazon IAM best practices when using AWS services in GitHub Actions workflows, including:

Permissions

This action requires the following minimum set of permissions to run an Automated Test:

NOTE:

${Account} should be replaced with the AWS Account Id where the test will run

${ProjectId} should be replaced with the Id of the AWS Device Farm being used if you wish to restrict the action to only one project, otherwise replace this with a *.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "devicefarm:ListProjects",
        "devicefarm:ListVPCEConfigurations",
        "devicefarm:ListJobs",
        "devicefarm:ListSuites",
        "devicefarm:ListTests",
        "devicefarm:ListArtifacts"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "devicefarm:ListNetworkProfiles",
        "devicefarm:ListDevicePools",
        "devicefarm:ListUploads",
        "devicefarm:CreateUpload"
      ],
      "Resource": "arn:aws:devicefarm:us-west-2:${Account}:project:${ProjectId}"
    },
    {
      "Effect": "Allow",
      "Action": [
        "devicefarm:ScheduleRun"
      ],
      "Resource": [
        "arn:aws:devicefarm:us-west-2:${Account}:project:${ProjectId}",
        "arn:aws:devicefarm:us-west-2:${Account}:devicepool:*",
        "arn:aws:devicefarm:us-west-2:${Account}:upload:*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": "devicefarm:GetRun",
      "Resource": [
        "arn:aws:devicefarm:us-west-2:${Account}:run:*",
        "arn:aws:devicefarm:us-west-2:${Account}:project:${ProjectId}"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "devicefarm:GetUpload",
        "devicefarm:ListUploads",
        "devicefarm:DeleteUpload"
      ],
      "Resource": [
        "arn:aws:devicefarm:us-west-2:${Account}:upload:*",
        "arn:aws:devicefarm:us-west-2:${Account}:project:${ProjectId}"
      ]
    }
  ]
}

Additional Capabilities

Inputs

License Summary

This code is made available under the MIT license.

Security Disclosures

If you would like to report a potential security issue in this project, please do not create a GitHub issue. Instead, please follow the instructions here or email AWS security directly.