From ee8f3d47bba5a0f2f011c7ee344d6b7cdaf3cf51 Mon Sep 17 00:00:00 2001 From: Xiaofeng Wang Date: Fri, 10 May 2019 13:56:19 +0800 Subject: [PATCH] Use real image building API to build image 1. move image building test to a separate file. So the tier-x test can ignore this test by excluding this file. 2. add all configurable settings before build image to increase test coverage --- test/end-to-end/pages/ViewBlueprint.page.js | 17 ++- test/end-to-end/specs/imageBuilding.test.js | 135 ++++++++++++++++++++ test/end-to-end/specs/viewBlueprint.test.js | 64 ---------- test/end-to-end/utils/commands.js | 2 +- test/vm.install | 3 - 5 files changed, 151 insertions(+), 70 deletions(-) create mode 100644 test/end-to-end/specs/imageBuilding.test.js diff --git a/test/end-to-end/pages/ViewBlueprint.page.js b/test/end-to-end/pages/ViewBlueprint.page.js index 7d3034f1b..5079d3451 100644 --- a/test/end-to-end/pages/ViewBlueprint.page.js +++ b/test/end-to-end/pages/ViewBlueprint.page.js @@ -347,11 +347,14 @@ class ViewBlueprintPage { } get completeLebel() { + // image building needs times to complete, so increase timeout to 40 minutes + // and checking interval to 2 seconds const selector = "span=Complete"; browser.waitUntil( () => browser.isExisting(selector), - timeout, - `Complete label under Images tab in View Blueprint page cannot be found by selector ${selector}` + timeout * 20, + `Complete label under Images tab in View Blueprint page cannot be found by selector ${selector}`, + 2000 ); return $(selector); } @@ -376,6 +379,16 @@ class ViewBlueprintPage { return $(selector); } + get imageDownloadButton() { + const selector = '.list-pf-actions [download=""]'; + browser.waitUntil( + () => browser.isExisting(selector), + timeout, + `Download button under Images tab in View Blueprint page cannot be found by selector ${selector}` + ); + return $(selector); + } + get stopButton() { const selector = "span=Stop"; browser.waitUntil( diff --git a/test/end-to-end/specs/imageBuilding.test.js b/test/end-to-end/specs/imageBuilding.test.js new file mode 100644 index 000000000..90e1007b3 --- /dev/null +++ b/test/end-to-end/specs/imageBuilding.test.js @@ -0,0 +1,135 @@ +const faker = require("faker"); +const commands = require("../utils/commands"); + +const Blueprint = require("../components/Blueprint.component"); +const blueprintsPage = require("../pages/blueprints.page"); +const ViewBlueprintPage = require("../pages/ViewBlueprint.page"); +const createUserAccount = require("../pages/createUserAccount.page"); +const CreateImagePage = require("../pages/CreateImage.page"); +const ToastNotificationPage = require("../pages/ToastNotification.page"); +const deleteImagePage = require("../pages/deleteImage.page"); + +describe("View Blueprint Page", function() { + const name = faker.lorem.slug(); + const description = faker.lorem.sentence(); + const blueprintComponent = new Blueprint(name); + const viewBlueprintPage = new ViewBlueprintPage(name, description); + const createImagePage = new CreateImagePage(name); + const toastNotificationPage = new ToastNotificationPage("imageWaiting"); + + before(function() { + commands.login(); + commands.startLoraxIfItDoesNotStart(); + + // create new blueprint with openssh-server installed + commands.newBlueprint(name, description); + blueprintComponent.blueprintNameLink.click(); + viewBlueprintPage.loading(); + + // set hostname + const hostname = faker.lorem.slug(); + viewBlueprintPage.editHostnameButton.click(); + viewBlueprintPage.hostnameInputBox.setValue(hostname); + viewBlueprintPage.okHostnameButton.click(); + + // add user admin with password and public key configured + const username = "admin"; + const password = "123qwe!@#QWE"; + const sshKey = + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhbIOLUndK2150PwjZqxEmYC/b0z1isMFUXyJ0n2Pl0gJoFk28WDJ4tNMBraqAGyxqHv2YyqaJEY54ne0Pb085b9+0bOiBWp7rRhzRUwOdYrMRYE6zAow4lPPKVu0cY/a2uIzXmGz6meK7nSZ3g+0cfsfs2z6vJ/ip/tgbNM6XCSmI63N0QezEUy8dxDLrA0C4PrTq3QPMF+lvi8njt6B/k6f3AzqcsIldN0MULBI3Hp98cjBkmhFS4ZFZ/EAe6ePPOezVorAxC/C/X/76mcbsJpEke9Cn0EPPbCODIa+tVXyZRYCK0l4pU4h5ShinQI0yvYA9Y3NcFyChRk25RAuR cockpit-composer@localhost.localhost"; + viewBlueprintPage.createUserAccountButton.click(); + createUserAccount.loading(); + createUserAccount.userNameBox.setValue(username); + createUserAccount.fullNameBox.setValue(username); + createUserAccount.roleCheckbox.click(); + createUserAccount.passwordBox.setValue(password); + createUserAccount.confirmPasswordBox.setValue(password); + createUserAccount.sshKeyBox.setValue(sshKey); + createUserAccount.createButton.click(); + browser.waitForExist(createUserAccount.containerSelector, timeout, true); + browser.waitForExist(`[data-tr=${username}] [data-td=username]`); + + // create tar image + viewBlueprintPage.createImageButton.click(); + createImagePage.loading(); + createImagePage.imageTypeSelect.selectByValue("tar"); + createImagePage.createButton.waitForEnabled(timeout); + createImagePage.createButton.click(); + browser.waitForExist(createImagePage.containerSelector, timeout, true); + toastNotificationPage.loadingInfoNotification(); + toastNotificationPage.close(); + viewBlueprintPage.imagesTab.click(); + }); + + after(function() { + // delete image + viewBlueprintPage.imageMoreButton.click(); + browser.keys("ArrowDown"); + browser.keys("Enter"); + deleteImagePage.loading(); + deleteImagePage.deleteImageButton.click(); + browser.waitForExist(deleteImagePage.containerSelector, timeout, true); + + // delete blueprint + viewBlueprintPage.backToBlueprintsLink.click(); + blueprintsPage.loading(); + commands.deleteBlueprint(name); + blueprintsPage.loading(); + }); + + it(`image name should contain blueprint name "${name}" and type "tar"`, function() { + expect(viewBlueprintPage.imageNameLabel.getText()) + .to.include(name) + .and.include("tar"); + }); + + it("image type should be tar", function() { + expect(viewBlueprintPage.imageTypeLabel("tar").getText()).to.equal("tar"); + }); + + it('should show "Complete"', function() { + // set test timeout to 40 minutes for image building case ONLY + this.timeout(timeout * 20); + expect(viewBlueprintPage.completeLebel.getText()).to.equal("Complete"); + }); + + it("should show correct Complete icon", function() { + expect(viewBlueprintPage.completeIcon.getAttribute("class")).to.include("pficon-ok"); + }); + + it("should show correct download API in download link", function() { + const link = viewBlueprintPage.imageDownloadButton.getAttribute("href"); + console.log(link); + const jsonStr = link.split("?")[1]; + + // decode base64 to json + const jsonObj = JSON.parse(Buffer.from(jsonStr, "base64").toString("ascii")); + + // get blueprint info from API + const endpoint = `/api/v0/compose/status/*?blueprint=${name}`; + const result = commands.apiFetchTest(endpoint).value; + // result looks like: + // https://github.com/weldr/lorax/blob/b57de934681056aa4f9bd480a34136cf340f510a/src/pylorax/api/v0.py#L819 + const uuid = JSON.parse(result.data).uuids[0].id; + + expect(jsonObj.path).to.equal(`/api/v0/compose/image/${uuid}`); + expect(jsonObj.unix).to.equal("/run/weldr/api.socket"); + }); + + describe("Delete Image Page", function() { + before(function() { + viewBlueprintPage.imageMoreButton.click(); + browser.keys("ArrowDown"); + browser.keys("Enter"); + deleteImagePage.loading(); + }); + + after(function() { + deleteImagePage.cancelButton.click(); + browser.waitForExist(deleteImagePage.containerSelector, timeout, true); + }); + it("Delete Image page should show correct blueprint name", function() { + expect(deleteImagePage.messageLabel.getText()).to.include(name); + }); + }); +}); diff --git a/test/end-to-end/specs/viewBlueprint.test.js b/test/end-to-end/specs/viewBlueprint.test.js index ac7e403b0..951cbdb77 100644 --- a/test/end-to-end/specs/viewBlueprint.test.js +++ b/test/end-to-end/specs/viewBlueprint.test.js @@ -182,69 +182,5 @@ describe("View Blueprint Page", function() { expect(viewBlueprintPage.selectedComponentFilter.getValue()).to.equal(blueprintManifest); }); }); - - describe("Create Image", function() { - const CreateImagePage = require("../pages/CreateImage.page"); - const ToastNotificationPage = require("../pages/ToastNotification.page"); - const deleteImagePage = require("../pages/deleteImage.page"); - const createImagePage = new CreateImagePage(name); - const toastNotificationPage = new ToastNotificationPage("imageWaiting"); - - before(function() { - viewBlueprintPage.createImageButton.click(); - createImagePage.loading(); - createImagePage.imageTypeSelect.selectByValue("tar"); - createImagePage.createButton.waitForEnabled(timeout); - createImagePage.createButton.click(); - browser.waitForExist(createImagePage.containerSelector, timeout, true); - toastNotificationPage.loadingInfoNotification(); - toastNotificationPage.close(); - viewBlueprintPage.imagesTab.click(); - }); - - after(function() { - viewBlueprintPage.imageMoreButton.click(); - browser.keys("ArrowDown"); - browser.keys("Enter"); - deleteImagePage.loading(); - deleteImagePage.deleteImageButton.click(); - browser.waitForExist(deleteImagePage.containerSelector, timeout, true); - }); - - it(`image name should contain blueprint name "${name}" and type "tar"`, function() { - expect(viewBlueprintPage.imageNameLabel.getText()) - .to.include(name) - .and.include("tar"); - }); - - it("image type should be tar", function() { - expect(viewBlueprintPage.imageTypeLabel("tar").getText()).to.equal("tar"); - }); - - it('should show "Complete"', function() { - expect(viewBlueprintPage.completeLebel.getText()).to.equal("Complete"); - }); - - it("should show correct Complete icon", function() { - expect(viewBlueprintPage.completeIcon.getAttribute("class")).to.include("pficon-ok"); - }); - - describe("Delete Image Page", function() { - before(function() { - viewBlueprintPage.imageMoreButton.click(); - browser.keys("ArrowDown"); - browser.keys("Enter"); - deleteImagePage.loading(); - }); - - after(function() { - deleteImagePage.cancelButton.click(); - browser.waitForExist(deleteImagePage.containerSelector, timeout, true); - }); - it("Delete Image page should show correct blueprint name", function() { - expect(deleteImagePage.messageLabel.getText()).to.include(name); - }); - }); - }); }); }); diff --git a/test/end-to-end/utils/commands.js b/test/end-to-end/utils/commands.js index ee54d5c0f..650eae19c 100644 --- a/test/end-to-end/utils/commands.js +++ b/test/end-to-end/utils/commands.js @@ -48,7 +48,7 @@ module.exports = { browser.keys("Enter"); // make sure new availabe components for new page loaded editBlueprintPage.loading(); - const filterContent = "httpd"; + const filterContent = "openssh-server"; editBlueprintPage.filterBox.setValue(filterContent); browser.keys("Enter"); browser.waitForExist(editBlueprintPage.filterContentLabel, timeout); diff --git a/test/vm.install b/test/vm.install index 16c8d33d6..f60accf48 100755 --- a/test/vm.install +++ b/test/vm.install @@ -17,9 +17,6 @@ fi # Install nodejs if it does not exist which node > /dev/null 2>&1 || yum install -y nodejs -# mock compose creation calls to backend for testing purposes -sed -i "s|\"/api/v0/compose\"|\"/api/v0/compose?test=2\"|" /usr/share/cockpit/welder/main.js - # disable https in cockpit and use http instead printf "[WebService]\\nAllowUnencrypted=true\\n" > /etc/cockpit/cockpit.conf