The repo is an Electron app that using CrossBrowserTesting API to do batch screenshots and display the results.
This app needs 3 services
- A CrossBrowserTesting Unlimited Account
- A Mongo DB: for save configs. The db can a be remote host from mLab or mongodb cloud or a local host.
- AWS Lambda: a serverless function for calling CrossBrowserTesting API to take screenshots
This repository includes 4 projects:
- common: shared code for electron and react
- react: the UI APP
- electron: the wrapper of the UI APP
- lambda: the screenshot task executor
Number 1 to 3 projects are written in Javascript and these projects are for the client App. To launch the app in development mode, you have to open 3 terminals and run:
# window 1 for common
$ cd common
$ npm run start
# window 2 for react
$ cd react
$ npm run start
# window 3 for electron
$ cd electron
$ npm run start
Number 4 project is written in C# with .Net Core 2.1 and it is for AWS Lambda. It can be only executed by AWS Lambda.
The client app is deploy to GitHub Release. Our CI server will be triggered by git Tag Push and automatically push files to Github.
To manually build the client app. you have to open 3 terminals and run:
# window 1 for common
$ cd common
$ npm run build
# window 2 for react
$ cd react
$ npm run build
# window 3 for electron
$ cd electron
$ npm run build
For lambda project, run these command to deploy to AWS Lambda
$ dotnet tool install -g Amazon.Lambda.Tools # for first time
$ dotnet lambda deploy-function cbt-screenshot-task # to upload the zip file
your machine must have a "swarm" profile in your ~/.aws/credentials and ~/.aws/configs for deployment or use --profile to give a specific profile.
The mongo database doesn't need to be set up, you just need to pass the connection string to the client app and lambda.
You can use docker to start a local mongodb
$ docker run -p 27017:27017 mongo
so the connection string is mongodb://localhost:27017/csa and the db name is csa
To setup the AWS Lambda, you need
- create a Aws lambda with name called "cbt-screenshot-task"
- the execution role needs Lambda Invoke permissions and CloudWatchLog Write permissions, the policy is like
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"lambda:InvokeFunction",
"lambda:InvokeAsync",
"logs:CreateLogGroup",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
- put Environment variables for "DB_CONNECTION_STRING" and "DB_NAME"
- create a AWS User on IAM for the APP, the permission needs
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction",
"lambda:InvokeAsync"
],
"Resource": "*"
}
]
}
- then put the AWS Access Key Id and AWS Access Key Secret via the client App on Setting Screen.
- Because CrossBrowserTesting doesn't have batch executing screenshots, so we create this app to do that.
- The app has a better list of pages to view the screenshot results than the original UI of CrossBrowserTesting
- The app supports quickly switching projects(websites)
- The database structure is
- project: store configs and pages
- pages: store the information of pages
- tasks: store the information of tasks
- The workflow is
- when you select pages to take screenshots, the app store the information into tasks collection.
- invoke AWS Lambda and the function will call CrossBrowserTesting API to take screenshots based on tasks collection.
- the app save the results in pages collection, so you can view the result via the app.