Skip to content

Instantly share code, notes, and snippets.

@schollz
Created February 1, 2022 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schollz/4f826623342acb24002671cc74283051 to your computer and use it in GitHub Desktop.
Save schollz/4f826623342acb24002671cc74283051 to your computer and use it in GitHub Desktop.
// @ts-check
const { test, expect } = require('@playwright/test');
const fs = require("fs");
// need to fill in the "XX"!
// data.json contains {"frame":x} where x is the frame to start
let rawdata = fs.readFileSync('data.json');
let data = JSON.parse(rawdata);
console.log(data);
data["frame"] = data["frame"] + 1;
if (data["frame"] > 4000) {
data["frame"] = 1000;
}
fs.writeFileSync('data.json', JSON.stringify(data));
var fileToUpload = `/XX/frame${data["frame"]}.png`;
test.use({ storageState: 'storageState.json' });
test.only('some test', async ({ page }) => {
console.log(`The random file is: ${fileToUpload}.`)
await page.goto('https://XX.bandcamp.com/edit_album?id=XX');
await page.click('button:has-text("X")');
await Promise.all([
page.waitForSelector('#edit-tralbum-form >> :nth-match(div:has-text("Upload Album Art 1400 x 1400 pixels minimum (bigger is better).jpg, .gif or .png"), 4)'),
]);
// Click #edit-tralbum-form >> :nth-match(div:has-text("Upload Album Art 1400 x 1400 pixels minimum (bigger is better).jpg, .gif or .png"), 4)
await page.click('#edit-tralbum-form >> :nth-match(div:has-text("Upload Album Art 1400 x 1400 pixels minimum (bigger is better).jpg, .gif or .png"), 4)');
await page.setInputFiles('input[type="file"]', fileToUpload);
await Promise.all([
page.waitForSelector('button:has-text("X")'),
]);
for (let i = 0; i < 16; i++) {
// change track titles
await Promise.all([
page.waitForSelector(`#track_id_${i}`),
]);
await page.click(`#track_id_${i}`);
// Press a with modifiers
await page.press(`input[name="track\\.title_${i}"]`, 'Control+a');
// Fill input[name="track\.title_5"]
await page.fill(`input[name="track\\.title_${i}"]`, randomLine[i]);
}
await page.click(':nth-match(a:has-text("Update"), 2)', { waitUntil: 'networkidle' });
await Promise.all([
page.waitForSelector('text=view album'),
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment