|
| 1 | +const { Given, When, Then, AfterAll } = require("@cucumber/cucumber"); |
| 2 | +const webdriver = require("selenium-webdriver"); |
| 3 | +const assert = require("assert"); |
| 4 | +const http2 = require("node:http2"); |
| 5 | + |
| 6 | +// Local development test |
| 7 | +// let driver = new Builder() |
| 8 | +// .forBrowser("chrome") |
| 9 | +// .setChromeOptions(new chrome.Options().headless()) |
| 10 | +// .build(); |
| 11 | + |
| 12 | +let driver = new webdriver.Builder() |
| 13 | + .forBrowser(webdriver.Browser.CHROME) |
| 14 | + .usingServer("http://localhost:4444/wd/hub") |
| 15 | + .build(); |
| 16 | + |
| 17 | +function isConnected(string) { |
| 18 | + return new Promise((resolve) => { |
| 19 | + const client = http2.connect("https://" + string); |
| 20 | + client.on("connect", () => { |
| 21 | + resolve(true); |
| 22 | + client.destroy(); |
| 23 | + }); |
| 24 | + client.on("error", () => { |
| 25 | + resolve(false); |
| 26 | + client.destroy(); |
| 27 | + }); |
| 28 | + }); |
| 29 | +} |
| 30 | + |
| 31 | +Given("The website {string} is available", async function (string) { |
| 32 | + return await isConnected(string); |
| 33 | +}); |
| 34 | + |
| 35 | +When("I navigate to {string}", async function (string) { |
| 36 | + return await driver.get("https://" + string); |
| 37 | +}); |
| 38 | + |
| 39 | +Then( |
| 40 | + "the page title should start with {string}", |
| 41 | + { timeout: 60 * 1000 }, |
| 42 | + async function (string) { |
| 43 | + return assert((await driver.getTitle()) == "Akarsh SEGGEMU"); |
| 44 | + } |
| 45 | +); |
| 46 | + |
| 47 | +AfterAll(async function () { |
| 48 | + await driver.quit(); |
| 49 | +}); |
0 commit comments