const { Builder, By, Key, until } = require('selenium-webdriver'); const chrome = require('selenium-webdriver/chrome'); const assert = require('assert'); async function validLogin() { const driver = await new Builder().forBrowser('chrome') .setChromeOptions(new chrome.Options() .addArguments('--headless') .addArguments('--no-sandbox') .addArguments('--disable-gpu') ) .build(); try { await driver.get(process.env.site_url); await driver.findElement(By.name('User')) .sendKeys('info@lufthansa.com'); await driver.findElement(By.name('Password')) .sendKeys('password1234'); await driver.findElement(By.name('Login')).click(); await driver.wait(until.elementLocated(By.xpath("//h2[text()='Flights']", 5000))) await driver.wait(until.elementLocated(By.name('CreateFlight'), 5000)) await driver.findElement(By.name('CreateFlight')).click(); await driver.wait(until.urlIs(process.env.site_url + "/create-flight")); await driver.wait(until.elementLocated(By.name('Gate'), 5000)) const Code = await driver.findElement(By.name('Code')); const Status = await driver.findElement(By.name('Status')) const Origin = await driver.findElement(By.name('Origin')) const Destination = await driver.findElement(By.name('Destination')) const ArrivalTime = await driver.findElement(By.name('ArrivalTime')) const DepartureTime = await driver.findElement(By.name('DepartureTime')) const Gate = await driver.findElement(By.name('Gate')) await Code.click(); await Code.clear(); await Code.sendKeys(process.env.code); await Status.click(); await Status.clear(); await Status.sendKeys('Scheduled'); await Origin.click(); await Origin.clear(); await Origin.sendKeys('Salta'); await Destination.click(); await Destination.clear(); await Destination.sendKeys('Buenos aires'); await ArrivalTime.sendKeys('03170020241155AM'); await DepartureTime.sendKeys('03170020240850AM'); await Gate.click(); await Gate.clear(); await Gate.sendKeys('A5'); await driver.wait(until.elementLocated(By.name('CreateFlightButton'), 5000)) await driver.findElement(By.name('CreateFlightButton')).click(); await driver.wait(until.elementLocated(By.xpath("//h2[text()='Flights']", 5000))) let actualUrl = process.env.site_url + "/home?page=1"; let expectedUrl = await driver.getCurrentUrl(); assert.equal(actualUrl, expectedUrl); driver.quit(); } catch (err) { console.error(err); process.exitCode = 1; driver.quit(); } } validLogin();