ocket8888 commented on code in PR #6805:
URL: https://github.com/apache/trafficcontrol/pull/6805#discussion_r864946687
##########
experimental/traffic-portal/nightwatch/globals/globals.ts:
##########
@@ -21,11 +53,97 @@ export interface GlobalConfig extends NightwatchGlobals {
adminPass: string;
adminUser: string;
trafficOpsURL: string;
+ apiVersion: string;
}
-const config = {
+const globals = {
adminPass: "twelve12",
adminUser: "admin",
+ apiVersion: "4.0",
+ before: async (done: () => void): Promise<void> => {
+ const apiUrl =
`${globals.trafficOpsURL}/api/${globals.apiVersion}`;
+ const client = axios.create({
+ httpsAgent: new https.Agent({
+ rejectUnauthorized: false
+ })
+ });
+ let accessToken = "";
+ const loginReq: LoginRequest = {
+ p: globals.adminPass,
+ u: globals.adminUser
+ };
+ try {
+ const resp = await client.post(`${apiUrl}/user/login`,
JSON.stringify(loginReq));
+ if(resp.headers["set-cookie"]) {
+ for (const cookie of
resp.headers["set-cookie"]) {
+ if(cookie.indexOf("access_token") > -1)
{
+ accessToken = cookie;
+ break;
+ }
+ }
+ }
+ } catch (e) {
+ console.error((e as AxiosError).message);
+ return Promise.reject();
Review Comment:
This is equivalent to `throw undefined`, which you'd never do. In fact, if
you just don't catch this at all, the Promise will reject with the thrown error
which will bubble up the call stack until something handles it or it crashes
the tests, in which case it gets logged for you.
##########
experimental/traffic-portal/nightwatch/tests/servers/servers.spec.ts:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed 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.
+ */
+
+/*
+* Licensed 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 {AugmentedBrowser} from "nightwatch/globals/globals";
+
+describe("Servers Spec", () => {
+ let augBrowser: AugmentedBrowser;
+ before(() => {
+ augBrowser = browser as AugmentedBrowser;
+ });
+
+ beforeEach(() => {
+ augBrowser.page.login()
+ .navigate().section.loginForm
+ .loginAndWait(augBrowser.globals.adminUser,
augBrowser.globals.adminPass);
+ });
+
+ it("Filter by hostname", async () => {
+ const page = augBrowser.page.servers();
+ page.navigate()
+ .pause(4000)
Review Comment:
I know this was in here already because I put it in, but is this actually
necessary? Even if it is, I think what I should've done instead was add 4
seconds to the element wait timeout.
##########
experimental/traffic-portal/nightwatch/tests/ds/ds.card.ts:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed 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 {type AugmentedBrowser} from "nightwatch/globals/globals";
+
+describe("DS Card Spec", () => {
+ let augBrowser: AugmentedBrowser;
+ before(() => {
+ augBrowser = browser as AugmentedBrowser;
+ });
+
+ beforeEach(() => {
+ augBrowser.page.login()
+ .navigate().section.loginForm
+ .loginAndWait(augBrowser.globals.adminUser,
augBrowser.globals.adminPass);
+ });
Review Comment:
Do you need to re-authenticate before *each* test?
##########
experimental/traffic-portal/nightwatch/globals/globals.ts:
##########
@@ -21,11 +53,97 @@ export interface GlobalConfig extends NightwatchGlobals {
adminPass: string;
adminUser: string;
trafficOpsURL: string;
+ apiVersion: string;
}
-const config = {
+const globals = {
adminPass: "twelve12",
adminUser: "admin",
+ apiVersion: "4.0",
+ before: async (done: () => void): Promise<void> => {
+ const apiUrl =
`${globals.trafficOpsURL}/api/${globals.apiVersion}`;
+ const client = axios.create({
+ httpsAgent: new https.Agent({
+ rejectUnauthorized: false
+ })
+ });
+ let accessToken = "";
+ const loginReq: LoginRequest = {
+ p: globals.adminPass,
+ u: globals.adminUser
+ };
+ try {
+ const resp = await client.post(`${apiUrl}/user/login`,
JSON.stringify(loginReq));
+ if(resp.headers["set-cookie"]) {
+ for (const cookie of
resp.headers["set-cookie"]) {
+ if(cookie.indexOf("access_token") > -1)
{
+ accessToken = cookie;
+ break;
+ }
+ }
+ }
+ } catch (e) {
+ console.error((e as AxiosError).message);
+ return Promise.reject();
+ }
+ if(accessToken === "") {
+ console.error("Access token is not set");
+ return Promise.reject();
+ }
+ client.defaults.headers.common = { Cookie: accessToken };
+
+ const cdn: CDN = {
+ dnssecEnabled: false, domainName: "tests.com", name:
"testCDN"
+ };
+ let respCDN: ResponseCDN;
+ try {
+ let resp = await client.post(`${apiUrl}/cdns`,
JSON.stringify(cdn));
+ respCDN = resp.data.response;
+
+ const ds: RequestDeliveryService = {
+ active: false,
+ cacheurl: null,
+ cdnId: respCDN.id,
+ displayName: "test DS",
+ dscp: 0,
+ ecsEnabled: false,
+ edgeHeaderRewrite: null,
+ fqPacingRate: null,
+ geoLimit: GeoLimit.NONE,
+ geoProvider: GeoProvider.MAX_MIND,
+ httpBypassFqdn: null,
+ infoUrl: null,
+ initialDispersion: 1,
+ ipv6RoutingEnabled: false,
+ logsEnabled: false,
+ maxOriginConnections: 0,
+ maxRequestHeaderBytes: 0,
+ midHeaderRewrite: null,
+ missLat: 0,
+ missLong: 0,
+ multiSiteOrigin: false,
+ orgServerFqdn: "http://test.com",
+ profileId: 1,
+ protocol: Protocol.HTTP,
+ qstringIgnore: 0,
+ rangeRequestHandling: 0,
+ regionalGeoBlocking: false,
+ remapText: null,
+ routingName: "test",
+ signed: false,
+ tenantId: 1,
+ typeId: 1,
+ xmlId: "testDS"
+ };
+ resp = await client.post(`${apiUrl}/deliveryservices`,
JSON.stringify(ds));
+ const respDS: ResponseDeliveryService =
resp.data.response[0];
+ console.log(`Successfully created DS
'${respDS.displayName}'`);
+ } catch(e) {
+ console.error((e as AxiosError).message);
+ return Promise.reject();
Review Comment:
same here
##########
experimental/traffic-portal/nightwatch/page_objects/deliveryServiceCard.ts:
##########
@@ -0,0 +1,77 @@
+/*
+* Licensed 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 {
+ EnhancedElementInstance,
+ EnhancedPageObject, EnhancedSectionInstance, NightwatchAPI
+} from "nightwatch";
+
+/**
+ * Defines the commands for the loginForm section
+ */
+interface DeliveryServiceCardCommands extends EnhancedSectionInstance,
EnhancedElementInstance<EnhancedPageObject> {
+ expandDS(xmlId: string): Promise<boolean>;
+ viewDetails(xmlId: string): Promise<boolean>;
+}
+
+/**
+ * Defines the loginForm section
+ */
+type DeliveryServiceCardSection =
EnhancedSectionInstance<DeliveryServiceCardCommands,
+ typeof deliveryServiceCardPageObject.sections.cards.elements>;
+
+/**
+ * Define the type for our PO
+ */
+export type DeliveryServiceCardPageObject = EnhancedPageObject<{}, {}, {
cards: DeliveryServiceCardSection }>;
+
+const deliveryServiceCardPageObject = {
+ api: {} as NightwatchAPI,
+ sections: {
+ cards: {
+ commands: {
+ async expandDS(xmlId: string): Promise<boolean>
{
+ return new Promise((resolve, reject) =>
{
+ this.click("css selector",
`mat-card#${xmlId}`, result => {
+ if (result.status ===
1) {
+ reject(new
Error(`Unable to find by css mat-card#${xmlId}`));
+ return;
+ }
+
this.waitForElementVisible(`mat-card#${xmlId} mat-card-content > div`,
+ undefined,
undefined, undefined, () => {
+
resolve(true);
+ });
+ });
+ });
+ },
+ async viewDetails(xmlId: string):
Promise<boolean> {
+ await this.expandDS(xmlId);
+ return new Promise((resolve) => {
+ this.click("css selector",
`mat-card#${xmlId} mat-card-actions > a`, () => {
+
browser.assert.urlContains("deliveryservice");
Review Comment:
Does the Promise reject if this assertion fails? If it doesn't the caller
might be unaware the navigation failed.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]