Taiko Automation

Using Taiko for user journey automation.

Software needed for script execution

Programming language used

Node package needed for script execution

  • Taiko - Install globally on your machine using the code
    npm install -g taiko
    ```  
- [Lighthouse](https://www.npmjs.com/package/lighthouse) - This is for generating Google Lighthouse reports. Install globally on your machine using the code below.
npm install -g lighthouse
```  
  • dotenv - This is for using variables in your code. Install globally on your machine using the code below.
    npm install -g dotenv
    ```  
- [Taiko Screencast plugin](https://www.npmjs.com/package/taiko-screencast) - This is for creating a gif for your code execution. Install globally on your machine using the code below.
npm install -g taiko-screencast
```  
  • Taiko Diagnostics plugin - This provides some diagnostics features like measuring speedindex, performance metrics of webpage. Install globally on your machine using the code below.
    npm install -g taiko-diagnostics
    ```

## Check installed node packages

```bash
npm list -g --depth 0

How to execute

  • Type the following in your terminal if you are executing the code from the folder in which the script exists
    taiko <filename>
    ```  
- Type the following in your terminal if you are executing the code from the **folder in which the script doesn't exist**
taiko <full file path with filename>
```

How to execute with plugin

  • Type the following in your terminal if you are executing the code from the folder in which the script exists
    taiko <filename> --plugin <plugin name>
    ```  
- Type the following in your terminal if you are executing the code from the **folder in which the script doesn't exist**
taiko <full file path with filename> --plugin <plugin name>
```

How to use environment variables

    setx <variable name> "value"
    ```

## Code execution demo on YouTube

- [Rapha.cc](https://www.youtube.com/watch?v=0ErzwZyZDgY) - _Taiko-Rapha.js_
- [BT.com](https://www.youtube.com/watch?v=-orYOGBYRQc) - _Taiko-BT.js_
- [The-Internet.Herokuapp.com](https://www.youtube.com/watch?v=dp1PeXhXYI4) - _Taiko-InternetHerokuApp.js_

## Container execution

#### NOTE - Please make sure the script you want to execute is running in headless mode

1. Clone this repo to your local machine
2. Change to repo directory
3. Build a docker image using the command
docker build -t <name-of-docker-image> .
```  

Sample output

    neo@ubuntu:~/Downloads/Taiko-Scripts$ sudo docker build -t taiko-new .
    Sending build context to Docker daemon  166.4kB
    Step 1/11 : FROM node:12.18.0-stretch-slim AS builder
    ---> 775e76326355
    ...
    Successfully tagged taiko-new:latest
    ```

1. Verify image created successfully by running following code
docker run -it <name-of-docker-image> bash
```
Sample output
    neo@ubuntu:~/Downloads/Taiko-Scripts$ sudo docker run -it taiko-new bash
    test@f0c2a6f3b48f:~/Taiko-Scripts$ ls -ltr
    total 108
    -rw-rw-r-- 1 test test 2516 Jun 26 13:16 Taiko-UltimateQA.js
    ...
    -rw-rw-r-- 1 test test 1463 Jun 26 13:16 Taiko-BT-Headless.js
    -rw-rw-r-- 1 test test 1739 Jun 26 13:16 README.md
    -rw-rw-r-- 1 test test  894 Jun 26 13:16 OB.ico
    -rw-rw-r-- 1 test test 1068 Jun 26 13:16 LICENSE
    -rw-rw-r-- 1 test test 1506 Jun 26 14:56 Dockerfile
    ```

1. Run Docker image using the command
docker run -t <name-of-docker-image>
```
Sample output
    neo@ubuntu:~/Downloads/Taiko-Scripts$ sudo docker run -t taiko-new
    ✔ Browser opened
    ✔ Navigated to URL http://google.com
    ...
    ✔ Browser closed
    ```

1. Run another Taiko script using the command
docker run -t <name-of-docker-image> taiko <name-of-taiko-script>
```
Sample output
    neo@ubuntu:~/Downloads/Taiko-Scripts$ sudo docker run -t taiko-new taiko Taiko-BT-Headless.js
    ✔ Browser opened
    ✔ Navigated to URL http://bt.com
    ...
    ✔ Browser closed
    ```

## Remove all docker resources

Clean all docker images/containers/volumes using this [bash script](https://gist.github.com/rafaelaazevedo/bec6cf339888bbac60336d01193ae923) by [Rafaela Azevedo](https://github.com/rafaelaazevedo)

## Syntax help

[Taiko documentation](https://docs.taiko.dev/)  
On this page