Skip to content

Commit

Permalink
Fix failed cypress tests in v1.4.0-rc5 and v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TachunLin committed Dec 3, 2024
1 parent 0edf843 commit 16568fb
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 51 deletions.
Binary file added cypress/.package-lock.json.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion cypress/pageobjects/image.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ImagePage extends CruResourcePo {
const keys = Object.keys(labels);

cy.get('body').click(0,0);
cy.get('.fixed-header-actions').contains('Filter Labels').click();
cy.get('.fixed-header-actions').contains('Filter labels').click();
cy.get('.filter-popup').contains('Clear All').click();
keys.forEach((key, index) => {
cy.get('.filter-popup').contains('Add').click();
Expand Down
3 changes: 1 addition & 2 deletions cypress/pageobjects/rancher.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ export class rancherPage {

cy.contains(constants.rancherUrl, { timeout: constants.timeout.timeout });

return cy.get('.copy');

return cy.get('.copy', { timeout: constants.timeout.timeout });
}

public registerRancher() {
Expand Down
2 changes: 1 addition & 1 deletion cypress/pageobjects/support.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class SupportPage {
}

public inputSupportBundle(description?: string, issueURL?: string): CypressChainable {
return cy.get("main .bundleModal").as("generateView").then($el => {
return cy.get(".modal-container.bundleModal").as("generateView").then($el => {
if (description) cy.wrap($el).get("textarea").type(description)
if (issueURL) cy.wrap($el).get("input").type(issueURL)

Expand Down
22 changes: 11 additions & 11 deletions cypress/pageobjects/virtualmachine.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@ export class VmsPage extends CruResourcePo {

clickVMSnapshotAction(name: string, snapshotName: string) {
this.clickAction(name, 'Take Virtual Machine Snapshot');
cy.get('.v--modal-box .card-title').find('h4').contains('Take Virtual Machine Snapshot');
cy.get('.modal-container .card-title').find('h4').contains('Take Virtual Machine Snapshot');

new LabeledInputPo('.v--modal-box .labeled-input', `:contains("Name *")`).input(snapshotName)
cy.get('.v--modal-box button').contains('Create').click();
new LabeledInputPo('.modal-container .labeled-input', `:contains("Name *")`).input(snapshotName)
cy.get('.modal-container button').contains('Create').click();
cy.get('.growl-container .growl-list').find('.growl-text div').contains('Succeed');
}


clickVMBackupAction(name: string, backupName: string) {
this.clickAction(name, 'Take Backup');
cy.get('.v--modal-box .card-title').find('h4').contains('Add Backup');
cy.get('.modal-container .card-title').find('h4').contains('Add Backup');

new LabeledInputPo('.v--modal-box .labeled-input', `:contains("Name")`).input(backupName)
cy.get('.v--modal-box button').contains('Create').click();
new LabeledInputPo('.modal-container .labeled-input', `:contains("Name")`).input(backupName)
cy.get('.modal-container button').contains('Create').click();
cy.get('.growl-container .growl-list').find('.growl-text div').contains('Succeed');
}

Expand Down Expand Up @@ -229,7 +229,7 @@ export class VmsPage extends CruResourcePo {
}
});

cy.get('.v--modal-box button').contains('Delete').click();
cy.get('[data-testid="prompt-remove-confirm-button"]').contains('Delete').click();
}

network() {
Expand Down Expand Up @@ -378,7 +378,7 @@ export class VmsPage extends CruResourcePo {
cy.wait('@delete').then(res => {
cy.window().then((win) => {
const id = `${namespace}/${name}`;
super.checkDelete(this.type, id, 80)
super.checkDelete(this.type, id, 240)
expect(res.response?.statusCode, `Delete ${this.type}`).to.be.oneOf([200, 204]);
})
})
Expand All @@ -389,14 +389,14 @@ export class VmsPage extends CruResourcePo {

cy.wrap(volumeNames).each((V: string) => {
this.clickAction(vmName, 'Add Volume').then((_) => {
cy.get('.v--modal-box,.v--modal .card-container').within(() => {
cy.get('.modal-container .card-container').within(() => {
this.plugVolumeCustomName().input(V);
})
this.plugVolumeName().select({ option: V });
})

cy.intercept('POST', `/v1/harvester/${this.realType}s/${namespace}/${vmName}*`).as('plug');
cy.get('.v--modal-box,.v--modal .card-container').contains('Apply').click();
cy.get('.modal-container .card-container').contains('Apply').click();
cy.wait('@plug').then(res => {
expect(res.response?.statusCode, `${this.type} plug Volume`).to.be.oneOf([200, 204]);
this.searchClear();
Expand All @@ -411,7 +411,7 @@ export class VmsPage extends CruResourcePo {
cy.wrap(volumeIndexArray).each((index: number) => {
cy.get('.info-box.box').eq(index).contains('Detach Volume').click();
cy.intercept('POST', `/v1/harvester/${this.realType}s/${namespace}/${vmName}*`).as('unplug');
cy.get('.v--modal-box,.v--modal .card-container').contains('Detach').click();
cy.get('.modal-container .card-container').contains('Detach').click();
cy.wait('@unplug').then(res => {
expect(res.response?.statusCode, `${this.type} unplug Volume`).to.be.oneOf([200, 204]);
})
Expand Down
6 changes: 3 additions & 3 deletions cypress/pageobjects/volume.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export class VolumePage extends CruResourcePo {

clickVolumeSnapshotAction(name: string, snapshotName: string) {
this.clickAction(name, 'Take Snapshot');
cy.get('.v--modal-box').find('.card-title').contains('Take Snapshot');
cy.get('.modal-container').find('.card-title').contains('Take Snapshot');

new LabeledInputPo('.v--modal-box .labeled-input', `:contains("Name")`).input(snapshotName)
cy.get('.v--modal-box button').contains('Create').click();
new LabeledInputPo('.modal-container .labeled-input', `:contains("Name")`).input(snapshotName)
cy.get('.modal-container button').contains('Create').click();
cy.get('.growl-container .growl-list').find('.growl-text div').contains('Succeed');
}

Expand Down
2 changes: 1 addition & 1 deletion cypress/pageobjects/volumeSnapshot.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export default class VolumeSnapshot extends CruResourcePo {
restoreNew(name: string, newVolumeName: string) {
this.clickAction(name, 'Restore');
new LabeledInputPo('.labeled-input', `:contains("New Volume Name")`).input(newVolumeName);
cy.get('.v--modal-box,.v--modal .card-actions').contains('Create').click();
cy.get('.modal-container,.card-wrap .card-actions').contains('Create').click();
}
}
2 changes: 1 addition & 1 deletion cypress/testcases/settings/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Set backup target S3', () => {
settings.checkIsCurrentPage(false);
})

it.only('Set backup target S3', () => {
it('Set backup target S3', () => {
settings.clickMenu('backup-target', 'Edit Setting', 'backup-target');

const backupTarget = Cypress.env('backupTarget');
Expand Down
3 changes: 3 additions & 0 deletions cypress/testcases/virtualmachines/virtual-machine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ describe("Delete VM with exported image", () => {

volumePO.goToList()
volumePO.exportImage(volumes[0].metadata.name, imageName)
imagePO.goToList()
imagePO.checkState({ name: imageName, size: '10 GB' }); // Check image state before delete vm

cy.intercept('DELETE', `/v1/harvester/kubevirt.io.virtualmachines/${namespace}/${VM_NAME}*`).as('deleteVM');
vms.delete(namespace, VM_NAME)
cy.wait('@deleteVM').then(res => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/testcases/volume/volumes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe("Edit volume increase size via form", () => {
buttonText: 'Add Volume',
create: false,
image: `default/${imageEnv.name}`,
size: 4
size: '10'
}];

// create VM
Expand All @@ -280,7 +280,7 @@ describe("Edit volume increase size via form", () => {
vms.checkState({ name: VM_NAME, state: 'Off' });

volumes.goToEdit(volumeName);
volumes.setBasics({ size: '5' });
volumes.setBasics({ size: '15' });
volumes.update(`${namespace}/${volumeName}`);

// check VOLUME state
Expand Down
56 changes: 28 additions & 28 deletions cypress/utils/components/cru-resource.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class CruResourcePo extends PagePo {
* @param realType: matches api.
* @param storeType: matches vuex.
*/
constructor({ type, realType, storeType}: {type: string, realType?: string, storeType?: string}) {
constructor({ type, realType, storeType }: { type: string, realType?: string, storeType?: string }) {
super(`/harvester/c/local/${type}`);

this.type = type
Expand All @@ -24,7 +24,7 @@ export default class CruResourcePo extends PagePo {

public type = '';
public realType = '';
public storeType: string|undefined = undefined;
public storeType: string | undefined = undefined;
public table = new TablePo();;
public footerButtons = '.cru-resource-footer'
public confirmRemove = '.card-container.prompt-remove'
Expand Down Expand Up @@ -62,51 +62,51 @@ export default class CruResourcePo extends PagePo {
cy.visit(`/harvester/c/local/${this.type}/create`)

this.setValue(value)

if (urlWithNamespace) {
this.save({namespace: value.namespace})
this.save({ namespace: value.namespace })
} else {
this.save()
}
}

public clone(id:string, value:any) {
public clone(id: string, value: any) {
cy.visit(`/harvester/c/local/${this.type}/${id}?mode=clone`)

this.setValue(value)

this.save()
}


public save({
namespace,
namespace,
buttonText = 'save',
edit,
} : {
namespace?:string,
buttonText?:string,
}: {
namespace?: string,
buttonText?: string,
edit?: boolean;
} = {}) {
if (namespace) {
cy.intercept('POST', `/v1/harvester/${this.realType}s/${namespace}`).as('create');
} else {
cy.intercept('POST', `/v1/harvester/${this.realType}s`).as('create');
}

this.clickFooterBtn(buttonText)
cy.wait('@create').then(res => {
expect(res.response?.statusCode, `Create ${this.type} success`).to.equal(201);
})
}

public delete(namespace:any, name:string, displayName?: string) {
public delete(namespace: any, name: string, displayName?: string) {
cy.visit(`/harvester/c/local/${this.type}`)

this.clickAction(displayName || name, 'Delete')

let id = '';

if (!namespace) {
id = name;
} else {
Expand All @@ -123,13 +123,13 @@ export default class CruResourcePo extends PagePo {
})
}

async deleteFromStore(id: string, realType: string=this.realType) {
async deleteFromStore(id: string, realType: string = this.realType) {
cy.window().then(async (win: any) => {
try {
const resource = await (win as any).$nuxt.$store.dispatch('harvester/find', { type: realType, id: id });
await resource.remove();
this.checkDelete(realType, id)
} catch(e: any) {
} catch (e: any) {
if (e.status === 404) {
cy.log(`The resource ${realType} does not exist`)
} else {
Expand Down Expand Up @@ -168,12 +168,12 @@ export default class CruResourcePo extends PagePo {
}

public setValue(value: any) {
this.namespace().select({option: value?.namespace})
this.namespace().select({ option: value?.namespace })
this.name().input(value?.name)
this.description().input(value?.description)
}

public update(id:string, type?: string) {
public update(id: string, type?: string) {
const _type = type || this.realType
cy.intercept('PUT', `/v1/harvester/${_type}s/${id}`).as('update');
cy.get(this.footerButtons).contains('Save').click()
Expand All @@ -182,7 +182,7 @@ export default class CruResourcePo extends PagePo {
})
}

public hasAction({name, nameIndex = 3, ns, nsIndex = 4, action, expect = true, nameSelector}: { name:string, nameIndex?:number, ns:string, nsIndex?:number, action: string, expect?:boolean, nameSelector?:string }) {
public hasAction({ name, nameIndex = 3, ns, nsIndex = 4, action, expect = true, nameSelector }: { name: string, nameIndex?: number, ns: string, nsIndex?: number, action: string, expect?: boolean, nameSelector?: string }) {
this.search(name);
cy.wait(2000);
cy.wrap('async').then(() => {
Expand All @@ -191,37 +191,37 @@ export default class CruResourcePo extends PagePo {
cy.get(`[data-testid="sortable-table-${rowIndex}-row"]`).find(this.actionMenuIcon).click();
cy.get(this.actionMenu).should(`${expect ? '' : 'not.'}contain`, action);
// click outside to close action menu
cy.get('body').click(0,0);
cy.get('body').click(0, 0);
}
})
});
}

public clickAction(name:string, action: string) {
public clickAction(name: string, action: string) {
this.search(name);
const record = cy.contains(name)
expect(record.should('be.visible'))
record.parentsUntil('tbody', 'tr').find(this.actionMenuIcon).click()
return cy.get(this.actionMenu).contains(action).click()
}

public checkEdit(name:string, namespace?:string, value?:any, action:string = 'Edit Config') {
public checkEdit(name: string, namespace?: string, value?: any, action: string = 'Edit Config') {
this.clickAction(name, action)

this.setValue(value)

if (namespace) {
this.update(`${namespace}/${name}`)
} else {
this.update(`${name}`)
}
}

public checkClone(name:string, namespace?:string, value?:any, action:string = 'Clone') {
public checkClone(name: string, namespace?: string, value?: any, action: string = 'Clone') {
this.clickAction(name, action)

this.setValue(value)

this.save()
}

Expand Down Expand Up @@ -251,7 +251,7 @@ export default class CruResourcePo extends PagePo {
cy.wrap('async').then(() => {
this.table.find(name, nameIndex, ns, nsIndex, options?.nameSelector).then((rowIndex: any) => {
if (typeof rowIndex === 'number') {
cy.get(`[data-testid="sortable-table-${rowIndex}-row"]`).find('td').eq(columnIndex - 1, {timeout: options?.timeout || constants.timeout.timeout}).should('contain', columnValue);
cy.get(`[data-testid="sortable-table-${rowIndex}-row"]`).find('td').eq(columnIndex - 1, { timeout: options?.timeout || constants.timeout.timeout }).should('contain', columnValue);
}
})
});
Expand All @@ -273,7 +273,7 @@ export default class CruResourcePo extends PagePo {
this.clickAction(name, 'Edit Config');
}

public goToDetail({name, nameIndex = 3, ns, nsIndex = 4, nameSelector}: { name:string, nameIndex?:number, ns:string, nsIndex?:number, nameSelector?:string }) {
public goToDetail({ name, nameIndex = 3, ns, nsIndex = 4, nameSelector }: { name: string, nameIndex?: number, ns: string, nsIndex?: number, nameSelector?: string }) {
this.goToList();
this.search(name);
cy.wait(2000);
Expand Down
2 changes: 1 addition & 1 deletion cypress/utils/components/page.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Header {
public static findNamespace(ns: string) {
cy.get('.top').find('.ns-filter').focus();
cy.get(`.ns-dropdown-menu .ns-options #ns_${ns} .ns-item div`).contains(ns);
cy.get('.top').find('.ns-filter .ns-values').click();
cy.get('.top').find('.ns-filter .ns-values').click({ force: true });
}
}

Expand Down

0 comments on commit 16568fb

Please sign in to comment.