diff --git a/cypress/pageobjects/image.po.ts b/cypress/pageobjects/image.po.ts index 3c4dde05d..31d6a7b1c 100644 --- a/cypress/pageobjects/image.po.ts +++ b/cypress/pageobjects/image.po.ts @@ -73,8 +73,8 @@ export class ImagePage { cy.get('.tab#labels').click(); keys.forEach((key, index) => { cy.contains('Add Label').click(); - cy.get('.kv-item.key input').eq(index + 2).type(key); - cy.get('.kv-item.value input').eq(index + 2).type(value.labels[key]); + cy.get('.kv-item.key input').eq(-1).type(key); + cy.get('.kv-item.value input').eq(-1).type(value.labels[key]); }); } @@ -125,10 +125,6 @@ export class ImagePage { cy.contains(value.name).parentsUntil('tbody', 'tr').find('td.col-image-percentage-bar').contains(valid ? 'Completed' : '0%', { timeout: constants.timeout.uploadTimeout }).should('be.visible'); // state indicator for status of image upload status e.g. active or uploading cy.contains(value.name).parentsUntil('tbody', 'tr').find('td.col-badge-state-formatter').contains(valid ? 'Active' : 'Failed', { timeout: constants.timeout.uploadTimeout }).should('be.visible'); - - if (valid) { - cy.contains(value.size || 'Size need to be string').should('be.visible'); - } } // public checkImageInLH(imageName: string) { diff --git a/cypress/pageobjects/volume.po.ts b/cypress/pageobjects/volume.po.ts index ec7ee81f7..e137bc2b0 100644 --- a/cypress/pageobjects/volume.po.ts +++ b/cypress/pageobjects/volume.po.ts @@ -67,7 +67,7 @@ export class VolumePage { cy.intercept('POST', `v1/harvester/persistentvolumeclaims/*/${ volumeName }?action=export`).as('exportImage'); cy.get(this.exportImageActions).contains('Create').click(); cy.wait('@exportImage').then(res => { - expect(res.response?.statusCode).to.equal(200); + expect(res.response?.statusCode, `Check Export Image`).to.be.oneOf([200, 204]); expect(cy.contains('Succeed')); }); } diff --git a/cypress/testcases/image/images.spec.ts b/cypress/testcases/image/images.spec.ts index 2a3e4f04b..fe9a21304 100644 --- a/cypress/testcases/image/images.spec.ts +++ b/cypress/testcases/image/images.spec.ts @@ -1,10 +1,53 @@ import YAML from 'js-yaml' import { VmsPage } from "@/pageobjects/virtualmachine.po"; import { ImagePage } from "@/pageobjects/image.po"; +import { generateName } from '@/utils/utils'; +import { HCI } from '@/constants/types'; const vms = new VmsPage(); const image = new ImagePage(); +describe('Auto setup image from cypress environment', () => { + it('Auto setup image from cypress environment', () => { + const imageEnv = Cypress.env('image'); + const IMAGE_NAME = imageEnv.name; + const IMAGE_URL = imageEnv.url; + + const value = { + name: IMAGE_NAME, + url: IMAGE_URL, + } + + cy.login(); + + cy.request({ + url: `v1/harvester/${HCI.IMAGE}s`, + headers: { + accept: 'application/json' + } + }).as('imageList') + + cy.get('@imageList').should((res: any) => { + expect(res?.status, 'Check Image list').to.equal(200); + const images = res?.body?.data || [] + + const imageEnv = Cypress.env('image'); + + const name = imageEnv.name + const url = imageEnv.url + const imageFound = images.find((i:any) => i?.spec?.displayName === name) + + if (imageFound) { + return + } else { + image.goToCreate(); + image.create(value); + image.checkState(value); + } + }) + }) +}) + /** * 1. Create image with cloud image available for openSUSE. http://download.opensuse.org/repositories/Cloud:/Images:/Leap_15.3/images/openSUSE-Leap-15.3.x86_64-NoCloud.qcow2 * 2. Click save @@ -19,12 +62,12 @@ const image = new ImagePage(); * 5. User should be able to create a new image with same name. */ describe('Create an image with valid image URL', () => { - const IMAGE_NAME = 'auto-image-valid-url-test'; - const IMAGE_URL = 'http://download.opensuse.org/repositories/Cloud:/Images:/Leap_15.3/images/openSUSE-Leap-15.3.x86_64-NoCloud.qcow2'; + const imageEnv = Cypress.env('image'); + const IMAGE_NAME = generateName('auto-image-valid-url-test'); + const IMAGE_URL = imageEnv.url; const value = { name: IMAGE_NAME, url: IMAGE_URL, - size: '544 MB', labels: { y1: 'z1', y2: 'z2' @@ -106,8 +149,8 @@ describe('Create an image with valid image URL', () => { * 1. image “img-1” will be deleted */ describe('Delete VM with exported image', () => { - const IMAGE_NAME = 'img-1'; - const VM_NAME = 'vm-1'; + const IMAGE_NAME = generateName('img-1'); + const VM_NAME = generateName('vm-1'); it('Delete VM with exported image', () => { cy.login(); @@ -137,14 +180,10 @@ describe('Delete VM with exported image', () => { image.goToList(); image.checkState({ name: IMAGE_NAME, - size: '10 GB' }); // delete VM vms.delete(namespace, VM_NAME); - - // delete IMAGE - image.delete(IMAGE_NAME); }); }); @@ -157,8 +196,8 @@ describe('Delete VM with exported image', () => { * 1. image “img-1” will be updated */ describe('Update image labels after deleting source VM', () => { - const IMAGE_NAME = 'img-1'; - const VM_NAME = 'vm-1'; + const IMAGE_NAME = generateName('img-1'); + const VM_NAME = generateName('vm-1'); it('Update image labels after deleting source VM', () => { cy.login(); @@ -273,8 +312,8 @@ describe('Update image labels after deleting source VM', () => { * 1. Image should upload. */ describe('Create a ISO image via upload', () => { - const IMAGE_NAME = 'auto-image-iso-upload-test'; - const VM_NAME = 'auto-image-iso-test-vm'; + const IMAGE_NAME = generateName('auto-image-iso-upload-test'); + const VM_NAME = generateName('auto-image-iso-test-vm'); it('Create a ISO image via upload', () => { cy.login();