-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathn26.js
64 lines (53 loc) · 1.69 KB
/
n26.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { sanitize } from './helpers.js';
const loginUrl = 'https://app.n26.com/login';
const logoutUrl = 'https://app.n26.com/logout';
const selectors = {
currentBalanceSpan: '#main > div:nth-child(2) > p > span',
emailInput: '#email',
loginBtn: 'button[type=submit]',
passwordInput: '#password',
pageNameP: '#a11y-page-name-paragraph',
};
const confirmLoginText = 'Confirm login on your phone';
const pageNameText = 'Home — N26';
const login = async (page, email, password) => {
await page.goto(loginUrl);
await page.waitForSelector(selectors.emailInput, { visible: true });
await page.type(selectors.emailInput, email);
await page.type(selectors.passwordInput, password);
await page.click(selectors.loginBtn);
// Because of 2FA the user needs to confirm the login on their phone
await page.waitForFunction(
(confirmLoginText) => {
return document.querySelector('h1') && document.querySelector('h1').textContent === confirmLoginText;
},
{},
confirmLoginText
);
// ... and then we need to wait until the homepage loads
await page.waitForFunction(
({ selector, pageNameText }) => {
return document.querySelector(selector) && document.querySelector(selector).textContent === pageNameText;
},
{},
{
pageNameText,
selector: selectors.pageNameP,
},
);
}
async function logout(page) {
await page.goto(logoutUrl);
}
async function getSummary(page) {
const $currentBalanceText = await page.$(selectors.currentBalanceSpan);
const currentBalanceText = await page.evaluate(element => element.textContent, $currentBalanceText);
return {
balance: sanitize(currentBalanceText),
};
}
export {
login,
logout,
getSummary,
};