github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/wats/test/login.js (about) 1 import test from 'ava'; 2 import Fly from '../helpers/fly'; 3 import Web from '../helpers/web'; 4 import puppeteer from 'puppeteer'; 5 6 test.beforeEach(async t => { 7 let url = process.env.ATC_URL || 'http://localhost:8080'; 8 let username = process.env.ATC_ADMIN_USERNAME || 'test'; 9 let password = process.env.ATC_ADMIN_PASSWORD || 'test'; 10 let teamName = 'main'; 11 let context = {}; 12 context.url = url; 13 context.fly = new Fly(url, username, password, teamName); 14 await context.fly.setupHome(); 15 context.web = await Web.build(url, username, password); 16 context.succeeded = false; 17 t.context = context; 18 }); 19 20 test.afterEach(async t => { 21 t.context.succeeded = true; 22 }); 23 24 test.afterEach.always(async t => { 25 if (t.context.web.page && !t.context.succeeded) { 26 await t.context.web.page.screenshot({path: 'failure.png'}); 27 } 28 if (t.context.web.browser) { 29 await t.context.web.browser.close(); 30 } 31 await t.context.fly.cleanup(); 32 }); 33 34 test('can fly login with browser and reuse same browser without CSRF issues', async t => { 35 let flyPromise = t.context.fly.spawn(`login -c ${t.context.url}`); 36 flyPromise.childProcess.stdout.on('data', async data => { 37 data.toString().split("\n").forEach(async line => { 38 if (line.includes(t.context.url)) { 39 await t.context.web.page.goto(line); 40 await t.context.web.performLogin(); 41 await t.context.web.page.click('#submit-login'); 42 } 43 }); 44 }); 45 await flyPromise; 46 let currentUrl = t.context.web.page.url(); 47 t.true(currentUrl.includes(`${t.context.url}/fly_success`)); 48 await t.context.web.waitForText('your token has been transferred'); 49 await t.context.fly.run('set-pipeline -n -p some-pipeline -c fixtures/states-pipeline.yml'); 50 await t.context.web.page.goto(t.context.web.route('/')); 51 const group = `.dashboard-team-group[data-team-name="main"]`; 52 let pipelineSelector = `${group} .card[data-pipeline-name="some-pipeline"]`; 53 let playButton = `${pipelineSelector} [style*="ic-play"]`; 54 let pauseButton = `${pipelineSelector} [style*="ic-pause"]`; 55 await t.context.web.scrollIntoView(group); 56 await t.context.web.page.waitFor(playButton); 57 await t.context.web.page.click(playButton); 58 await t.context.web.page.waitForSelector(pauseButton, {timeout: 90000}); 59 t.pass(); 60 61 await t.context.fly.run('destroy-pipeline -n -p some-pipeline'); 62 }); 63 64 test('password input does not autocomplete', async t => { 65 await t.context.web.page.goto(t.context.web.route('/sky/login')); 66 let passwordInput = await t.context.web.page.waitForSelector('#password', {timeout: 90000}); 67 const autocomplete = await t.context.web.page.evaluate(body => body.getAttribute('autocomplete'), passwordInput); 68 await passwordInput.dispose(); 69 t.is(autocomplete, 'off'); 70 });