Skip to content

Commit 8e2315c

Browse files
author
Naduni Pamudika
committed
Fix review comments
1 parent fcd25fb commit 8e2315c

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

tests/cypress/integration/devportal/001-applications/03-generate-api-keys.spec.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ describe("Application tests", () => {
2727
let testApiId;
2828

2929
const createAppForTest = () => {
30-
cy.visit('/devportal/applications/create?tenant=carbon.super');
3130
cy.intercept('**/application-attributes').as('attrGet');
31+
cy.intercept('POST', '**/applications').as('createAppReq');
32+
cy.visit('/devportal/applications/create?tenant=carbon.super');
3233
cy.wait('@attrGet', { timeout: 300000 });
3334

3435
cy.get('#application-name').type(appName);
@@ -44,24 +45,13 @@ describe("Application tests", () => {
4445

4546
cy.get('#itest-application-create-save').click({ force: true });
4647

47-
// Accept either redirect-based or in-page success patterns.
48-
cy.location('pathname', { timeout: 120000 }).then((pathname) => {
49-
if (pathname.includes('/overview')) {
50-
cy.get('#itest-info-bar-application-name', { timeout: 30000 })
51-
.contains(appName)
52-
.should('exist');
53-
appCreated = true;
54-
} else {
55-
cy.get('body').then(($body) => {
56-
if ($body.find('#itest-info-bar-application-name').length > 0) {
57-
cy.get('#itest-info-bar-application-name', { timeout: 30000 })
58-
.contains(appName)
59-
.should('exist');
60-
appCreated = true;
61-
}
62-
});
63-
}
48+
// Prefer API success + listing verification over fragile UI timing checks.
49+
cy.wait('@createAppReq', { timeout: 120000 }).then(({ response }) => {
50+
expect(response, 'application create response').to.exist;
51+
expect([200, 201, 202], 'application create status').to.include(response.statusCode);
6452
});
53+
54+
appCreated = true;
6555
};
6656
const openSecurityRestrictionSelect = () => {
6757
cy.get('[role="dialog"]').last().within(() => {
@@ -108,13 +98,24 @@ describe("Application tests", () => {
10898
checkIfKeyExists();
10999
};
110100

101+
const openRuntimeConfigurations = () => {
102+
cy.get('body', { timeout: 60000 }).then(($body) => {
103+
if ($body.find('#itest-api-details-api-config-acc').length > 0) {
104+
cy.get('#itest-api-details-api-config-acc').click({ force: true });
105+
} else if ($body.find('#itest-api-config').length > 0) {
106+
cy.get('#itest-api-config').click({ force: true });
107+
}
108+
});
109+
110+
cy.get('#left-menu-itemRuntimeConfigurations', { timeout: 100000 }).click({ force: true });
111+
};
112+
111113
it("Generate API Keys", () => {
112114
cy.loginToPublisher(publisher, password);
113115
Utils.addAPIWithEndpoints({ name: apiName, version: apiVersion, context: apiContext }).then((apiId) => {
114116
testApiId = apiId;
115117
cy.visit(`/publisher/apis/${apiId}/overview`);
116-
cy.get('#itest-api-details-api-config-acc').click();
117-
cy.get('#left-menu-itemRuntimeConfigurations').click();
118+
openRuntimeConfigurations();
118119
cy.wait(2000);
119120
cy.get('#applicationLevel').click();
120121
cy.wait(1000);

tests/cypress/integration/devportal/002-subscriptions/04-generate-keys-api-details-page.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ describe("Generate keys from api details page", () => {
9797

9898
after(() => {
9999
if (appCreated) {
100-
cy.visit('/devportal/applications?tenant=carbon.super');
101100
cy.intercept('**/applications**').as('appGet');
101+
cy.visit('/devportal/applications?tenant=carbon.super');
102102
cy.wait('@appGet', { timeout: 300000 }).then(() => {
103103
cy.get('body').then(($body) => {
104104
if ($body.find(`#delete-${appName}-btn`).length > 0) {

tests/cypress/support/commands.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,18 @@ Cypress.Commands.add('createApp', (appName, appDescription) => {
552552
});
553553

554554
Cypress.Commands.add('deleteApp', (appName) => {
555-
cy.visit(`/devportal/applications?tenant=carbon.super`);
556555
cy.intercept('**/applications**').as('appGet');
556+
cy.visit(`/devportal/applications?tenant=carbon.super`);
557557
cy.wait('@appGet', { timeout: 300000 }).then(() => {
558-
cy.get(`#delete-${appName}-btn`, { timeout: 30000 });
559-
cy.get(`#delete-${appName}-btn`).click({ force: true });
560-
cy.get(`#itest-confirm-application-delete`).click();
558+
const deleteButtonSelector = `[id="delete-${appName}-btn"]`;
559+
cy.get('body', { timeout: 30000 }).then(($body) => {
560+
if ($body.find(deleteButtonSelector).length > 0) {
561+
cy.get(deleteButtonSelector, { timeout: 30000 }).first().click({ force: true });
562+
cy.get('#itest-confirm-application-delete', { timeout: 30000 }).click();
563+
} else {
564+
cy.log(`Skipping deleteApp: application ${appName} is not listed.`);
565+
}
566+
});
561567
})
562568
});
563569

0 commit comments

Comments
 (0)