Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS-SELENIUM] Create class for interaction with workspace API #13295

Closed
wants to merge 10 commits into from
66 changes: 44 additions & 22 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"@types/mocha": "^5.2.6",
"@types/node": "^11.13.4",
"@types/selenium-webdriver": "^3.0.16",
"axios": "^0.18.0",
monaka marked this conversation as resolved.
Show resolved Hide resolved
"chai": "^4.2.0",
"chromedriver": "^2.46.0",
"mocha": "^6.1.4",
"selenium-webdriver": "^3.6.0",
"ts-node": "^8.0.3",
"typed-rest-client": "^1.2.0",
"typescript": "^3.4.3"
},
"dependencies": {
Expand Down
92 changes: 92 additions & 0 deletions e2e/test-files/che7-java-workspace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"defaultEnv": "default",
"environments": {
"default": {
"machines": {
"ws/dev": {
"attributes": {
"memoryLimitBytes": "536870912"
},
"servers": {},
"volumes": {
"projects": {
"path": "/projects"
}
},
"installers": [],
"env": {}
}
},
"recipe": {
"type": "kubernetes",
"content": "kind: List\nitems:\n - \n apiVersion: v1\n kind: Pod\n metadata:\n name: ws\n spec:\n containers:\n - \n image: 'eclipse/che-dev:nightly'\n name: dev\n resources:\n limits:\n memory: 512Mi\n",
"contentType": "application/x-yaml"
}
}
},
"projects": [
{
"links": [],
"name": "console-java-simple",
"attributes": {
"language": [
"java"
]
},
"type": "maven",
"source": {
"location": "https://github.com/che-samples/console-java-simple.git",
"type": "git",
"parameters": {}
},
"path": "/console-java-simple",
"description": "A hello world Java application.",
"mixins": [],
"problems": []
}
],
"name": "wksp-w7uz",
"attributes": {
"editor": "eclipse/che-theia/1.0.0",
"plugins": "eclipse/che-machine-exec-plugin/0.0.1,redhat/java/0.38.0"
},
"commands": [
{
"commandLine": "mvn -Duser.home=${HOME} -f ${CHE_PROJECTS_ROOT}/console-java-simple clean install",
"name": "console-java-simple:maven build",
"attributes": {
"goal": "Build",
"previewUrl": ""
},
"type": "mvn"
},
{
"commandLine": "mvn -Duser.home=${HOME} -f ${CHE_PROJECTS_ROOT}/console-java-simple clean install \njava -jar ${CHE_PROJECTS_ROOT}/console-java-simple/target/*.jar",
"name": "console-java-simple:maven build and run",
"attributes": {
"goal": "Run",
"previewUrl": ""
},
"type": "mvn"
},
{
"commandLine": "cd ${CHE_PROJECTS_ROOT}/console-java-simple; gradle build",
"name": "console-java-simple:gradle build",
"attributes": {
"goal": "Build",
"previewUrl": ""
},
"type": "gralde"
},
{
"commandLine": "cd ${CHE_PROJECTS_ROOT}/console-java-simple; gradle run",
"name": "console-java-simple:gradle run",
"attributes": {
"goal": "Run",
"previewUrl": ""
},
"type": "gradle"
}
],
"links": []
}
4 changes: 0 additions & 4 deletions e2e/tests/HappyPath.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { WorkspaceDetailsPlugins } from "../pageobjects/dashboard/workspace-deta
import { Ide } from "../pageobjects/ide/Ide";
import { ProjectTree } from "../pageobjects/ide/ProjectTree";
import { Editor } from "../pageobjects/ide/Editor";
import { DriverHelper } from "../utils/DriverHelper";
import { By, Key } from "selenium-webdriver";

const workspaceName: string = NameGenerator.generate("wksp-test-", 5);
const namespace: string = "che";
Expand All @@ -37,8 +35,6 @@ const ide: Ide = e2eContainer.get(CLASSES.Ide)
const projectTree: ProjectTree = e2eContainer.get(CLASSES.ProjectTree)
const editor: Editor = e2eContainer.get(CLASSES.Editor)

const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper)

suite("E2E", async () => {

suite("Login and wait dashboard", async () => {
Expand Down
73 changes: 73 additions & 0 deletions e2e/utils/workspace/TestWorkspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import axios from 'axios';
import { TestConstants } from '../../TestConstants';
import fs from 'fs'

export class TestWorkspace {
private static readonly PATH_TO_CONF_FILE: string = "test-files/che7-java-workspace.json";
private static readonly API_ENDPOINT: string = TestConstants.TS_SELENIUM_BASE_URL + "/api/";
private static readonly WORKSPACE_API_URL: string = TestWorkspace.API_ENDPOINT + "workspace";
private workspaceId: string = "";
private workspaceIdeUrl: string = "";

constructor(private readonly workspaceName: string, private workspaceConfig?: any) {
this.workspaceName = workspaceName;

if (workspaceConfig) {
this.workspaceConfig = workspaceConfig;
}

if (!workspaceConfig) {
let fileText: string = fs.readFileSync(TestWorkspace.PATH_TO_CONF_FILE, "utf8")
this.workspaceConfig = JSON.parse(fileText)
}

this.createWorkspace(workspaceName);
}

private async createWorkspace(workspaceName: string) {
this.workspaceConfig.name = workspaceName;

axios.post(TestWorkspace.WORKSPACE_API_URL, this.workspaceConfig)
.then(resp => {
let responceData = resp.data;
this.workspaceId = responceData.id;
this.workspaceIdeUrl = responceData.links.ide;
})
.then(() => {
this.startWorkspace();
});
};

getName(): string {
return this.workspaceName;
}

getId(): string {
return this.workspaceId;
}

getIdeUrl(): string {
return this.workspaceIdeUrl;
}

startWorkspace() {
let workspaceApiUrl: string = `${TestWorkspace.API_ENDPOINT}workspace/${this.getId()}/runtime`;
axios.post(workspaceApiUrl)
}

deleteWorkspace() {
let workspaceApiUrl: string = `${TestWorkspace.API_ENDPOINT}workspace/${this.getId()}`;
axios.delete(workspaceApiUrl)

}

}
17 changes: 8 additions & 9 deletions e2e/utils/workspace/TestWorkspaceUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { injectable, inject } from 'inversify';
import { DriverHelper } from '../DriverHelper';
import { CLASSES } from '../../inversify.types';
import 'reflect-metadata';
import * as rm from 'typed-rest-client/RestClient'
import axios from 'axios'

export enum WorkspaceStatus {
RUNNING = 'RUNNING',
Expand All @@ -23,23 +23,22 @@ export enum WorkspaceStatus {

@injectable()
export class TestWorkspaceUtil {
constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper,
private readonly rest: rm.RestClient = new rm.RestClient('rest-samples')) { }
constructor(@inject(CLASSES.DriverHelper) private readonly driverHelper: DriverHelper) { }

public async waitWorkspaceStatus(namespace: string, workspaceName: string, expectedWorkspaceStatus: WorkspaceStatus) {
const workspaceStatusApiUrl: string = `${TestConstants.TS_SELENIUM_BASE_URL}/api/workspace/${namespace}:${workspaceName}`;
const attempts: number = TestConstants.TS_SELENIUM_WORKSPACE_STATUS_ATTEMPTS;
const polling: number = TestConstants.TS_SELENIUM_WORKSPACE_STATUS_POLLING;

for (let i = 0; i < attempts; i++) {
const response: rm.IRestResponse<any> = await this.rest.get(workspaceStatusApiUrl)
const response = await axios.get(workspaceStatusApiUrl)

if (response.statusCode !== 200) {
if (response.status !== 200) {
await this.driverHelper.wait(polling)
continue
}

const workspaceStatus: string = await response.result.status
const workspaceStatus: string = await response.data.status

if (workspaceStatus === expectedWorkspaceStatus) {
return;
Expand All @@ -57,14 +56,14 @@ export class TestWorkspaceUtil {
const polling: number = TestConstants.TS_SELENIUM_PLUGIN_PRECENCE_POLLING;

for (let i = 0; i < attempts; i++) {
const response: rm.IRestResponse<any> = await this.rest.get(workspaceStatusApiUrl)
const response = await axios.get(workspaceStatusApiUrl)

if (response.statusCode !== 200) {
if (response.status !== 200) {
await this.driverHelper.wait(polling)
continue
}

const machines: string = JSON.stringify(response.result.runtime.machines);
const machines: string = JSON.stringify(response.data.runtime.machines);
const isPluginPresent: boolean = machines.search(pluginName) > 0;

if (isPluginPresent) {
Expand Down