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
106 changes: 64 additions & 42 deletions e2e/package-lock.json

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

12 changes: 6 additions & 6 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
"@types/mocha": "^5.2.6",
"@types/node": "^11.13.4",
"@types/selenium-webdriver": "^3.0.16",
"chai": "^4.2.0",
"axios": "^0.17.1",
"chai": "^4.1.2",
"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"
"ts-node": "^8.1.0",
monaka marked this conversation as resolved.
Show resolved Hide resolved
"typescript": "^3.4.5"
monaka marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {
"inversify": "^5.0.1",
"reflect-metadata": "^0.1.13"
"inversify": "^4.13.0",
"reflect-metadata": "^0.1.8"
}
}
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)

}

}
Loading