Skip to content

Commit

Permalink
virtual shoppers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Bartus committed Aug 7, 2023
1 parent ea99903 commit 7ec66a6
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ flowchart LR

```mermaid
flowchart LR
vm[randomhack vm] --> container[randomhack container]
rhvm[randomhack vm] --> container[randomhack container]
container --> site[whoami-demo.freetls.fastly.net]
ptvm[puppeteer vm] --> scripts[puppeteer scripts]
scripts --> site
```


Expand Down
42 changes: 42 additions & 0 deletions puppeteer.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
resource "google_compute_instance" "puppeteer" {
name = "${var.site_name}-puppeteer"
machine_type = "c3-standard-4"
depends_on = [fastly_service_vcl.demo_service]
allow_stopping_for_update = true
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-2304-amd64"
}
}
network_interface {
network = "default"
access_config {}
}
metadata = {
ssh-keys = "ubuntu:${file("${var.ssh_pub_key}")}"
}
metadata_startup_script = "apt install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libxcomposite1 libxdamage1 libxfixes3 libcups2 libdrm2 libxrandr2 libgbm1 libasound2 libpangocairo-1.0-0 libgtk-3-0"
connection {
type = "ssh"
user = "ubuntu"
private_key = file("${var.ssh_priv_key}")
host = self.network_interface.0.access_config.0.nat_ip
}
provisioner "file" {
source = "puppets/"
destination = "/home/ubuntu"
}
provisioner "remote-exec" {
inline = [
"curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash",
"export NVM_DIR=\"$HOME/.nvm\"",
"[ -s \"$NVM_DIR/nvm.sh\" ] && \\. \"$NVM_DIR/nvm.sh\"",
"nvm install node",
"npm install puppeteer",
"export SITE_URL=https://${var.site_name}.freetls.fastly.net",
"nohup bash -c 'while true; do node homepage.js && sleep `shuf -i 2-10 -n1`; done &'",
"sleep 5 && nohup bash -c 'while true; do node promobutton.js && sleep `shuf -i 2-10 -n1`; done &'",
"sleep 10 && nohup bash -c 'while true; do node shopper.js && sleep `shuf -i 2-10 -n1`; done &'",
]
}
}
14 changes: 14 additions & 0 deletions puppets/homepage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch({headless: "new"});
const page = await browser.newPage();
await page.setViewport({width: 1600, height: 900});
await page.goto(process.env.SITE_URL);
await page.mouse.wheel({deltaY: 1000});
await page.waitForTimeout(100);
await page.mouse.wheel({deltaY: 1000});
await page.waitForTimeout(100);
//await page.screenshot({ path: 'homepage.png' });
await browser.close();
})();
18 changes: 18 additions & 0 deletions puppets/promobutton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch({headless: "new"});
const page = await browser.newPage();
await page.setViewport({width: 1600, height: 900});
await page.goto(process.env.SITE_URL);
await page.waitForTimeout(2000);
await page.waitForSelector('.action.more.button')
await page.click('.action.more.button');
await page.waitForTimeout(2000);
await page.mouse.wheel({deltaY: 1000});
await page.waitForTimeout(100);
await page.mouse.wheel({deltaY: 1000});
await page.waitForTimeout(100);
//await page.screenshot({ path: 'promobutton.png' });
await browser.close();
})();
27 changes: 27 additions & 0 deletions puppets/shopper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch({headless: "new"});
const page = await browser.newPage();
await page.setViewport({width: 1600, height: 900});
await page.goto(process.env.SITE_URL);
await page.waitForTimeout(2000);
await page.click('a[href$="sale.html"]');
await page.waitForTimeout(2000);
await page.click('#maincontent > div.columns > div.sidebar.sidebar-main > div > div > ul:nth-child(2) > li:nth-child(2) > a');
await page.waitForTimeout(2000);
await page.mouse.wheel({deltaY: 500});
await page.waitForTimeout(100);
await page.click('#product-item-info_1316 > a > span > span > img');
await page.waitForTimeout(2000);
await page.click('#option-label-size-144-item-168');
await page.waitForTimeout(500);
await page.click('#option-label-color-93-item-56');
await page.waitForTimeout(500);
await page.click('#product-addtocart-button > span');
await page.waitForTimeout(2000);
await page.click('#maincontent > div.page.messages > div:nth-child(2) > div > div > div > a');
await page.waitForTimeout(2000);
//await page.screenshot({ path: 'shopper.png' });
await browser.close();
})();

0 comments on commit 7ec66a6

Please sign in to comment.