Deploy Moon on Azure and Google Cloud
Quick way to set up parallel execution for Playwright and Selenium
In this short article we will see how we can easily set up Moon (Selenoid on Kubernetes) on Azure and Google Cloud to enable parallel execution for Playwright and Selenium.

Before we begin, lets quickly understand what is Moon
Moon is basically a browser automation solution which uses Kubernetes to launch browsers. Moon is built by the Aerokube team who are also responsible for building Selenoid.
The main difference between Selenoid and Moon is that the former is easily deployable in cloud virtual machines while the latter is super simple to deploy using Kubernetes or OpenShift.
For me, the most fascinating feature about Moon is the ability to execute Playwright tests remotely and in parallel. We know by now, that Playwright is superfast. However when we are looking at a huge volume of test cases, we need an infrastructure to be able to execute so many tests remotely.
Moon comes to the rescue. In the next segment we will see, how we can create a cluster in Google and Azure Clouds and run some very basic commands to have Moon up and ready in practically no time!
Google Cloud
Step 1: Go to your Google Cloud Platform Console and search for GKE (Google Kubernetes Engine). If you do not have a GCP account you can create one by following these steps.
Step 2: Create a standard [Cluster] . I chose the following parameters. You can choose data that suits you.
a. Cluster Name : moon
b. Zone : europe-west1-b
c. Number of Nodes :1
d. Machine Type : 2 vCPUs 8.00 GB
Step 3: Connect to the cluster by clicking on the [Run in Cloud Shell] button

Step 4: Once you are inside the Google Cloud Shell, run the following command :
$ git clone https://github.com/aerokube/moon-deploy.git && cd moon-deploy && kubectl apply -f moon.yaml
Step 5: To obtain Moon load balancer IP address, use the following command:
$ kubectl get svc -n moon

The EXTERNAL-IP (in the above case, it is 34.77.128.69 ) is of importance for us. We will see shortly what to do with it.
Azure Cloud
Step 1: Go to your Azure Portal and open up Azure Cloud Shell.
Step 2: Create a standard [Cluster] . The following command when executed from Azure Cloud Shell will create the cluster for you.
$ az aks create --resource-group TestAutomation --name moon --node-count 1 --generate-ssh-keys
In the above command, TestAutomation is the name of my Resource Group. You can create a new Resource Group if you don’t have any, by running the following command in cloud shell:
$ az group create --name TestAutomation --location eastus

Step 3: Connect to the cluster by running on the cloud shell the following command :
$ az account set --subscription <your subscription id>
$ az aks get-credentials --resource-group TestAutomation --name moon

Step 4: Now deploy moon in the cluster using the following command :
$ git clone https://github.com/aerokube/moon-deploy.git && cd moon-deploy && kubectl apply -f moon.yaml
Step 5 : To obtain Moon load balancer IP address, use the following command:
$ kubectl get svc -n moon

The EXTERNAL-IP (in the above case, it is 52.186.103.162 ) is of importance for us.
Okay, now that we have got the Moon load balancer IP (either from Azure Cloud or Google Cloud) its time for the moment of truth!
We hit the following URL in a browser and Voila!!
The Selenoid UI comes up!!

But the job is only half done.. We need to also trigger our Playwright scripts to execute tests on Moon.
For that, we will make a small change in our Playwright Scripts.
Instead of using the launch() function like the following :
const { chromium} = require('playwright');
(async () => {
var browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://www.example.com/');
await browser.close();
})();
We will use the connect() function like so :
let moonHostIp = '52.186.103.162'; //This the External IPasync() =>{
var browser = await chromium.connect({
timeout: 0,
wsEndpoint: 'ws://'+moonHostIp+':4444/playwright/chromium',
});
const page = await browser.newPage();
await page.goto('https://www.example.com/');
await browser.close();
})();
And if you want additional parameters to be used, you can use it in this way :
var browser = await firefox.connect({ wsEndpoint: 'ws://moon.example.com:4444/playwright/firefox?headless=false&enableVideo=true&screenResolution=1280x1024' });
Happy Testing!!
Important Links :
https://github.com/aerokube/moon
https://aerokube.com/moon/
Thanks Alexander Andryashin for your articles on Moon !!