|
7 | 7 | * not use this file except in compliance with the License. |
8 | 8 | * You may obtain a copy of the License at |
9 | 9 | * |
10 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
11 | 11 | * |
12 | 12 | * Unless required by applicable law or agreed to in writing, |
13 | 13 | * software distributed under the License is distributed on an |
14 | 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | | - * KIND, either express or implied. See the License for the |
| 15 | + * KIND, either express or implied. See the License for the |
16 | 16 | * specific language governing permissions and limitations |
17 | 17 | * under the License. |
18 | 18 | */ |
19 | 19 |
|
| 20 | +import { delay } from 'bluebird'; |
20 | 21 | import { FtrProviderContext } from '../ftr_provider_context'; |
21 | 22 |
|
22 | 23 | export function LoginPageProvider({ getService }: FtrProviderContext) { |
23 | 24 | const testSubjects = getService('testSubjects'); |
| 25 | + const log = getService('log'); |
| 26 | + const find = getService('find'); |
| 27 | + |
| 28 | + const regularLogin = async (user: string, pwd: string) => { |
| 29 | + await testSubjects.setValue('loginUsername', user); |
| 30 | + await testSubjects.setValue('loginPassword', pwd); |
| 31 | + await testSubjects.click('loginSubmit'); |
| 32 | + await find.waitForDeletedByCssSelector('.kibanaWelcomeLogo'); |
| 33 | + await find.byCssSelector('[data-test-subj="kibanaChrome"]', 60000); // 60 sec waiting |
| 34 | + }; |
| 35 | + |
| 36 | + const samlLogin = async (user: string, pwd: string) => { |
| 37 | + try { |
| 38 | + await find.clickByButtonText('Login using SAML'); |
| 39 | + await find.setValue('input[name="email"]', user); |
| 40 | + await find.setValue('input[type="password"]', pwd); |
| 41 | + await find.clickByCssSelector('.auth0-label-submit'); |
| 42 | + await find.byCssSelector('[data-test-subj="kibanaChrome"]', 60000); // 60 sec waiting |
| 43 | + } catch (err) { |
| 44 | + log.debug(`${err} \nFailed to find Auth0 login page, trying the Auth0 last login page`); |
| 45 | + await find.clickByCssSelector('.auth0-lock-social-button'); |
| 46 | + } |
| 47 | + }; |
24 | 48 |
|
25 | 49 | class LoginPage { |
26 | 50 | async login(user: string, pwd: string) { |
27 | | - await testSubjects.setValue('loginUsername', user); |
28 | | - await testSubjects.setValue('loginPassword', pwd); |
29 | | - await testSubjects.click('loginSubmit'); |
| 51 | + if ( |
| 52 | + process.env.VM === 'ubuntu18_deb_oidc' || |
| 53 | + process.env.VM === 'ubuntu16_deb_desktop_saml' |
| 54 | + ) { |
| 55 | + await samlLogin(user, pwd); |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + await regularLogin(user, pwd); |
| 60 | + } |
| 61 | + |
| 62 | + async logoutLogin(user: string, pwd: string) { |
| 63 | + await this.logout(); |
| 64 | + await this.sleep(3002); |
| 65 | + await this.login(user, pwd); |
| 66 | + } |
| 67 | + |
| 68 | + async logout() { |
| 69 | + await testSubjects.click('userMenuButton'); |
| 70 | + await this.sleep(500); |
| 71 | + await testSubjects.click('logoutLink'); |
| 72 | + log.debug('### found and clicked log out--------------------------'); |
| 73 | + await this.sleep(8002); |
| 74 | + } |
| 75 | + |
| 76 | + async sleep(sleepMilliseconds: number) { |
| 77 | + log.debug(`... sleep(${sleepMilliseconds}) start`); |
| 78 | + await delay(sleepMilliseconds); |
| 79 | + log.debug(`... sleep(${sleepMilliseconds}) end`); |
30 | 80 | } |
31 | 81 | } |
32 | 82 |
|
33 | 83 | return new LoginPage(); |
34 | 84 | } |
| 85 | + |
0 commit comments