"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const server_1 = require("./server");
const puppeteer_1 = __importDefault(require("puppeteer"));
const assert_1 = __importDefault(require("assert"));
const path_1 = __importDefault(require("path"));
describe('Sanity UI test', () => {
    let browser;
    let browserContext;
    let page;
    before(async () => {
        await server_1.openServer(9876, path_1.default.resolve(__dirname, 'fixtures', '.screenplay', 'server-basic'));
        browser = await puppeteer_1.default.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
    });
    after(async () => {
        await browser.close();
        server_1.closeServer();
    });
    beforeEach(async () => {
        browserContext = await browser.createIncognitoBrowserContext();
        page = await browserContext.newPage();
    });
    afterEach(async () => {
        await page.close();
        await browserContext.close();
    });
    it('UI test 1', async () => {
        await page.goto('http://localhost:9876?test=server-basic');
        const numberOfSteps = await page.evaluate(() => document.querySelectorAll('#sidebar > div').length);
        assert_1.default.equal(numberOfSteps, 7);
        await page.click('#sidebar > div:nth-child(2)');
        const selectedStepTitle = await page.evaluate(() => { var _a; return (_a = document.querySelector('.step-name')) === null || _a === void 0 ? void 0 : _a.textContent; });
        assert_1.default.equal(selectedStepTitle, '2.page-click');
    });
});
