MuukTest offers now integration with Playwright. With that, you can download and execute your tests using a Playwright script written on TypeScript. This way to execute a test is local in your machine and you can modify the script if you want to do that.
To execute a test using Playwright, you need to follow the next steps.
Prerequisites
Verify that you have installed the following packages and files:
- Node.js stable version (recommended 14.x.x Fermium)
- Your Key.pub from your MuukTest account. You can download it from your Account in Portal.
Node.js installation (skip this section if you already have the minimum required version installed)
To ensure you are using the required Node.js version run the steps below to install it
- Create a new folder, you can choose any name for it, and can be located anywhere, in this example we are naming it Playwright.
-
muukadmin@MuukLap:~$ mkdir playwright
-
- After you create the new directory, access it to continue the installation.
-
muukadmin@MuukLap:~$ cd playwright/
muukadmin@MuukLap:~/playwright$
-
- Run the following command to get the required Node.js version.
-
muukadmin@MuukLap:~$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
-
- Install Node.js 14.x and npm.
-
muukadmin@MuukLap:~$ sudo apt-get install -y nodejs
-
- You may also need development tools to build native addons, to acquire them run the following command.
-
muukadmin@MuukLap:~$ sudo apt-get install gcc g++ make
-
- Check that you have in deed the required version installed.
-
muukadmin@MuukLap:~$ node -v
v14.21.3
-
And that's it! In this article, you will learn how to install and configure Playwright to use with your tests.
Install & Configuration
1. Go to the folder you created previously on the Node.js installation section. If you skipped that section, then create a new directory to use Playwright. You can decide where and the name.
2. Open your Key.pub and copy the code that you see there. Next, with the following command, create an environment variable with the content:
export KEY="key"
Where key is the value that you copy from the Key.pub file.
3. Switch to the new folder and then install Playwright using the next command:
npm init playwright@latest
We have to select TypeScript as a language to use:
You can use the directory that you want but for this example is better to use tests:
On GitHub Actions Workflow, put the question in false:
Enable use Playwright browsers with true:
And then, left the next option about more dependencies on false, at this moment we don't need more.
In your command line, you will see this output while you are installing it.
4. Install axios using the next command:
npm install axios
5. Get a token and assign it to an environment variable. This is done via API, which you can do with the next command:
curl -X POST https://portal.muuktest.com:8081/generate_token_executer -k -d '{"key": "'"$KEY"'"}' -H "Content-Type: application/json"
Where $KEY is the environment variable that we created before with the content for your key.pub file.
You will receive an output like this.
To create your environment variables, you need to do the next command:
export TOKEN="token" export USERID="userid"
Where you will replace token with your token output and userid with your userid output.
6. Download the playwright configuration files using the next command:
curl -X POST https://portal.muuktest.com:8081/api/v1/downloadpwfiles -k -d '{"key": "'"$KEY"'"}' -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -o ./config.zip
Where $KEY is the environment variable that we created before with the content for your key.pub file.
7. Unzip the config.zip, and confirm that you have the next files: playwright.config.ts, reporter.ts, and utils.ts, and then copy them into the base folder.
With these steps, you can use Playwright and can start to download and execute tests.
Execute a test
Once you installed and configured Playwright, you can start to execute tests with them. To download your MuukTest test and execute it, you need to follow the next steps:
1. Download scrips using the next command:
curl -X POST https://portal.muuktest.com:8081/download_byproperty -H "Authorization: Bearer $TOKEN" -k -d '{"property": "tag", "value": ["TC#"], "platform": "pw", "userId": "'"$USERID"'"}' -H "Content-Type: application/json" -o ./test.zip
If you see the command, you use the environment variables that we created before (TOKEN & USERID). The only thing that you need to change is your TC#, which corresponds to the Test ID in MuukTest Portal.
If you see your zip downloaded, you can continue with the next step.
2. Unzip the downloaded file in a directory called test. You can create the directory before and extract the items there.
3. To execute your test, use the next command:
npx playwright test --headed
When your test starts to execute, a Chrome window will be opened with the steps that you recording on MuukTest.
Depending on your test result, you will receive an output like this in your console:
You can go to MuukTest Portal to see the execution result.
And that's all! 🎉
Enjoy using MuukTest + Playwright.
Comments
0 comments
Please sign in to leave a comment.