114 lines
3.1 KiB
TypeScript
114 lines
3.1 KiB
TypeScript
import playwright from "npm:playwright";
|
|
|
|
if (import.meta.main) {
|
|
main();
|
|
}
|
|
|
|
const devSpacename = Deno.env.get("BAS_DEVSPACE")!;
|
|
|
|
async function main() {
|
|
const browser = await playwright.chromium.launch({
|
|
headless: false,
|
|
});
|
|
const context = await browser.newContext();
|
|
const page = await context.newPage();
|
|
|
|
// stuff
|
|
await page.goto(Deno.env.get("BAS_URL")!);
|
|
await page.locator(`text=${Deno.env.get("BAS_PROFILE")!}`).click();
|
|
await page
|
|
.getByLabel("Email or User Name")
|
|
.fill(Deno.env.get("BAS_USERNAME")!);
|
|
await page.getByLabel("Password").fill(Deno.env.get("BAS_PASSWORD")!);
|
|
await page.waitForTimeout(500);
|
|
await page.getByText("Keep me signed in").check();
|
|
await page.waitForTimeout(500);
|
|
await page.getByText("Continue").click();
|
|
await page.waitForLoadState();
|
|
await page.waitForURL("**/index.html");
|
|
|
|
// Request manager without iframe directly
|
|
await page.goto(Deno.env.get("BAS_URL")! + "/workspace-manager-ui/");
|
|
await page.waitForTimeout(1000);
|
|
console.log(`Loaded management page`);
|
|
|
|
// const pageSource = await page.content();
|
|
// console.log(JSON.stringify(pageSource));
|
|
|
|
const devSpaceEl = await findCorrectDevspace(page);
|
|
if (!devSpaceEl) {
|
|
console.log;
|
|
throw Error(`Could not find devspace: ${devSpacename}`);
|
|
}
|
|
await startDevSpace(devSpaceEl);
|
|
await loadVSCode(devSpaceEl);
|
|
// await expect(page.locator('css=a.runningStatus')).toBeVisible()
|
|
|
|
// await expect(spaces.locator('a.runningStatus')).toHaveText('RUNNING');
|
|
// spaces.locator('a.hyperlink').click()
|
|
// spaces..
|
|
|
|
// Close on done
|
|
await new Promise((resolve) => {
|
|
page.on("close", resolve); // <-- add this
|
|
});
|
|
|
|
await context.close();
|
|
await browser.close();
|
|
}
|
|
|
|
async function findCorrectDevspace(page: playwright.Page) {
|
|
const rows = await page
|
|
.locator('div.dev-spaces-row:has-text("' + devSpacename + '")')
|
|
.all();
|
|
|
|
let findFullStack = false;
|
|
if (rows.length > 1) {
|
|
console.log(`Found multiple "${devSpacename}" dev spaces`);
|
|
findFullStack = true;
|
|
}
|
|
|
|
for (const el of rows) {
|
|
console.log(`Checking dev space row`);
|
|
const fullstack = await el
|
|
.locator(
|
|
'div.left-row:has-text("Full-Stack Application Using Productivity Tools")'
|
|
)
|
|
.isVisible();
|
|
|
|
if (fullstack) {
|
|
console.log(`Found the fullstack dev space row`);
|
|
}
|
|
|
|
// Skip non-fullstack lines if they exist for that name
|
|
if (findFullStack && !fullstack) {
|
|
continue;
|
|
}
|
|
return el;
|
|
}
|
|
}
|
|
|
|
async function startDevSpace(devSpaceEl: playwright.Locator) {
|
|
const running = await devSpaceEl
|
|
.locator('div.text-center a:has-text("RUNNING")')
|
|
.isVisible();
|
|
|
|
if (running) {
|
|
console.log(`Dev Space already running`);
|
|
return true;
|
|
}
|
|
|
|
await devSpaceEl.locator('button[id^="startButton"]').click()
|
|
|
|
await devSpaceEl
|
|
.locator('div.text-center a:has-text("STARTING")')
|
|
.isVisible();
|
|
console.log(`starting...`)
|
|
|
|
}
|
|
|
|
async function loadVSCode(devSpaceEl: playwright.Locator) {
|
|
console.log(`Opening VSCode dev space`)
|
|
await devSpaceEl.locator('a:has-text("' + devSpacename + '")').click();
|
|
}
|