You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/02/25 18:26:00 UTC

[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5579: Add TP login test and fix login function

ocket8888 commented on a change in pull request #5579:
URL: https://github.com/apache/trafficcontrol/pull/5579#discussion_r583058964



##########
File path: traffic_portal/test/integration/specs/Login.spec.ts
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { browser } from 'protractor';
+import { LoginPage } from '../PageObjects/LoginPage.po';
+import { TopNavigationPage } from '../PageObjects/TopNavigationPage.po';
+import { API } from '../CommonUtils/API';
+import { isMainThread } from 'worker_threads';
+
+let fs = require('fs')
+let using = require('jasmine-data-provider');

Review comment:
       can you use the same import style as the other imports? Like `import { readFileSync } from "fs"` and `import { * as using } from "jasmine-data-provider"`?

##########
File path: traffic_portal/test/integration/specs/Login.spec.ts
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { browser } from 'protractor';
+import { LoginPage } from '../PageObjects/LoginPage.po';
+import { TopNavigationPage } from '../PageObjects/TopNavigationPage.po';
+import { API } from '../CommonUtils/API';
+import { isMainThread } from 'worker_threads';
+
+let fs = require('fs')
+let using = require('jasmine-data-provider');
+let filename = 'Data/Login/TestCases.json';
+let testData = JSON.parse(fs.readFileSync(filename));
+
+let api = new API();
+let topNavigation = new TopNavigationPage();
+let loginPage = new LoginPage();

Review comment:
       These are all unmodified; could be `const`

##########
File path: traffic_portal/test/integration/PageObjects/LoginPage.po.ts
##########
@@ -29,24 +29,38 @@ export class LoginPage extends BasePage{
     private config = require('../config');
     private randomize = this.config.randomize;
 
-    async Login(userName: string, password: string ){
-        if(userName == 'admin'){
-            await this.txtUserName.sendKeys(userName)
-            await this.txtPassword.sendKeys(password)
+    async Login(login){
+        let result = false;
+        let basePage = new BasePage();
+        if(login.username == 'admin'){
+            await this.txtUserName.sendKeys(login.username)
+            await this.txtPassword.sendKeys(login.password)
             await browser.actions().mouseMove(this.btnLogin).perform();
             await browser.actions().click(this.btnLogin).perform();    
         }else{
-            await this.txtUserName.sendKeys(userName+this.randomize)
-            await this.txtPassword.sendKeys(password)
+            await this.txtUserName.sendKeys(login.username+this.randomize)
+            await this.txtPassword.sendKeys(login.password)
             await browser.actions().mouseMove(this.btnLogin).perform();
             await browser.actions().click(this.btnLogin).perform();    
         }
+        if(await browser.getCurrentUrl() == 'https://localhost/#!/login'){

Review comment:
       `==` could be `===`

##########
File path: traffic_portal/test/integration/PageObjects/LoginPage.po.ts
##########
@@ -29,24 +29,38 @@ export class LoginPage extends BasePage{
     private config = require('../config');
     private randomize = this.config.randomize;
 
-    async Login(userName: string, password: string ){
-        if(userName == 'admin'){
-            await this.txtUserName.sendKeys(userName)
-            await this.txtPassword.sendKeys(password)
+    async Login(login){
+        let result = false;
+        let basePage = new BasePage();

Review comment:
       `basePage` is never modified, could be `const`

##########
File path: traffic_portal/test/integration/specs/Login.spec.ts
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { browser } from 'protractor';
+import { LoginPage } from '../PageObjects/LoginPage.po';
+import { TopNavigationPage } from '../PageObjects/TopNavigationPage.po';
+import { API } from '../CommonUtils/API';
+import { isMainThread } from 'worker_threads';

Review comment:
       This import looks unused

##########
File path: traffic_portal/test/integration/specs/Login.spec.ts
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { browser } from 'protractor';
+import { LoginPage } from '../PageObjects/LoginPage.po';
+import { TopNavigationPage } from '../PageObjects/TopNavigationPage.po';
+import { API } from '../CommonUtils/API';
+import { isMainThread } from 'worker_threads';
+
+let fs = require('fs')
+let using = require('jasmine-data-provider');
+let filename = 'Data/Login/TestCases.json';
+let testData = JSON.parse(fs.readFileSync(filename));
+
+let api = new API();
+let topNavigation = new TopNavigationPage();
+let loginPage = new LoginPage();
+
+using(testData.LoginTest, async function(loginData){
+    using(loginData.Login, function(login){
+        describe('Traffic Portal - Login - '+ login.description, function(){
+            it('can open login page', async function(){
+                browser.get(browser.params.baseUrl);
+            })
+            it(login.description, async function(){
+                expect(await loginPage.Login(login)).toBeTruthy();
+            })
+        })
+    })
+})

Review comment:
       Missing newline at EOF

##########
File path: traffic_portal/test/integration/PageObjects/LoginPage.po.ts
##########
@@ -29,24 +29,38 @@ export class LoginPage extends BasePage{
     private config = require('../config');
     private randomize = this.config.randomize;
 
-    async Login(userName: string, password: string ){
-        if(userName == 'admin'){
-            await this.txtUserName.sendKeys(userName)
-            await this.txtPassword.sendKeys(password)
+    async Login(login){
+        let result = false;
+        let basePage = new BasePage();
+        if(login.username == 'admin'){

Review comment:
       `==` could be `===`

##########
File path: traffic_portal/test/integration/PageObjects/LoginPage.po.ts
##########
@@ -29,24 +29,38 @@ export class LoginPage extends BasePage{
     private config = require('../config');
     private randomize = this.config.randomize;
 
-    async Login(userName: string, password: string ){
-        if(userName == 'admin'){
-            await this.txtUserName.sendKeys(userName)
-            await this.txtPassword.sendKeys(password)
+    async Login(login){

Review comment:
       Missing typing on `Login` function. You could just do `login: {password: string, username: string}`, or make a separate type (which is just what I like to do, personally) and do
   
   ```typescript
   interface LoginData {
       password: string;
       username: string;
   }
   
   //...
   
   async function Login(login: LoginData): Promise<boolean> {
       //...
   }
   ```

##########
File path: traffic_portal/test/integration/PageObjects/LoginPage.po.ts
##########
@@ -29,24 +29,38 @@ export class LoginPage extends BasePage{
     private config = require('../config');
     private randomize = this.config.randomize;
 
-    async Login(userName: string, password: string ){
-        if(userName == 'admin'){
-            await this.txtUserName.sendKeys(userName)
-            await this.txtPassword.sendKeys(password)
+    async Login(login){
+        let result = false;
+        let basePage = new BasePage();
+        if(login.username == 'admin'){
+            await this.txtUserName.sendKeys(login.username)
+            await this.txtPassword.sendKeys(login.password)
             await browser.actions().mouseMove(this.btnLogin).perform();
             await browser.actions().click(this.btnLogin).perform();    
         }else{
-            await this.txtUserName.sendKeys(userName+this.randomize)
-            await this.txtPassword.sendKeys(password)
+            await this.txtUserName.sendKeys(login.username+this.randomize)
+            await this.txtPassword.sendKeys(login.password)
             await browser.actions().mouseMove(this.btnLogin).perform();
             await browser.actions().click(this.btnLogin).perform();    
         }
+        if(await browser.getCurrentUrl() == 'https://localhost/#!/login'){
+            result = await basePage.GetOutputMessage().then(function (value) {
+                if (login.validationMessage == value) {

Review comment:
       `==` could be `===`, but also it looks like you could just return this condition, I think even just in a "fat-arrow" function like `value=> value === login.validationMessage`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org