Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit d815c64

Browse files
Implement pause session functionality along with other ui improvements. (#30)
1 parent 6b4cbf5 commit d815c64

38 files changed

+799
-118
lines changed

migrations/001_create_table.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var createSessionTable = function (queryInterface, Sequelize) {
5555
start_time: { type: Sequelize.DATE, allowNull: false },
5656
end_time: { type: Sequelize.DATE, defaultValue: null },
5757
is_test_passed: { type: Sequelize.BOOLEAN, allowNull: true },
58+
is_paused: { type: Sequelize.BOOLEAN, allowNull: true, default: false },
5859
session_status: {
5960
type: Sequelize.ENUM,
6061
values: ["PASSED", "FAILED", "TIMEOUT", "RUNNING"],

package-lock.json

Lines changed: 83 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@
2828
"mainClass": "AppiumDashboardPlugin"
2929
},
3030
"dependencies": {
31-
"@appium/base-plugin": "^1.7.2",
31+
"@appium/base-plugin": "^1.8.0",
3232
"@ffmpeg-installer/ffmpeg": "^1.1.0",
3333
"@mui/icons-material": "^5.0.4",
3434
"@mui/material": "^5.0.4",
3535
"appium-base-driver": "^7.10.1",
36+
"async-lock": "^1.3.0",
37+
"async-wait-until": "^2.0.12",
3638
"bluebird": "^3.7.2",
3739
"body-parser": "^1.19.0",
3840
"circular-json": "^0.5.9",
3941
"cors": "^2.8.5",
4042
"debug": "^4.3.2",
4143
"express": "^4.17.1",
44+
"lodash": "^4.17.21",
4245
"lokijs": "^1.5.12",
4346
"react-ga": "^3.3.0",
4447
"reflect-metadata": "^0.1.13",
@@ -51,7 +54,9 @@
5154
"winston": "^3.3.3"
5255
},
5356
"devDependencies": {
57+
"@types/async-lock": "^1.1.3",
5458
"@types/express": "^4.17.13",
59+
"@types/lodash": "^4.14.178",
5560
"@types/lokijs": "^1.5.7",
5661
"@types/node": "^16.10.2",
5762
"@types/uuid": "^8.3.1",

src/app/commons/base-controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Request, Response, Router } from "express";
2+
import { Config } from "../../config";
23
import { IExpressController, IExpressRequest } from "../../interfaces/express-controller";
34
import { ExpressUtils } from "../utils/express-utils";
45

56
export abstract class BaseController implements IExpressController {
6-
abstract initializeRoutes(router: Router, config: any): void;
7+
abstract initializeRoutes(router: Router, config: Config): void;
78

89
public sendPaginatedResponse(result: { rows: any[]; count: number }, request: IExpressRequest, response: Response) {
910
if (request.parsedQuery.paginate == true) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { NextFunction, Router, Request, Response } from "express";
2+
import { EventEmitter } from "events";
3+
import { BaseController } from "../commons/base-controller";
4+
import { Config } from "../../config";
5+
6+
export class DebugController extends BaseController {
7+
constructor(private debugEventEmitter: EventEmitter) {
8+
super();
9+
}
10+
11+
public initializeRoutes(router: Router, config: Config) {
12+
router.post("/:sessionId/:state", this.changeSessionState.bind(this));
13+
}
14+
15+
public async changeSessionState(request: Request, response: Response, next: NextFunction) {
16+
let { sessionId, state } = request.params;
17+
if (!state.match("play|pause")) {
18+
return this.sendFailureResponse(response, "Invalid state. Supported states are play,pause");
19+
}
20+
this.debugEventEmitter.emit(sessionId, {
21+
event: "change_state",
22+
state,
23+
});
24+
return this.sendSuccessResponse(response, "Changed session state");
25+
}
26+
}

src/app/controllers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { SessionController } from "./session-controller";
22
export { BuildController } from "./build-controller";
33
export { ProjectController } from "./project-controller";
4+
export { DebugController } from "./debug-controller";

src/app/controllers/session-controller.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,18 @@ export class SessionController extends BaseController {
8686
},
8787
});
8888

89-
if (session) {
89+
if (session && session.session_status != "RUNNING") {
9090
await session.destroy();
9191
if (session.video_path) {
9292
fs.unlinkSync(session.video_path);
9393
}
9494
fs.rmdirSync(path.join(config.screenshotSavePath, session.session_id), { recursive: true });
95+
this.sendSuccessResponse(response, {
96+
success: true,
97+
});
98+
} else {
99+
this.sendFailureResponse(response, "Cannnot delete running session");
95100
}
96-
this.sendSuccessResponse(response, {
97-
success: true,
98-
});
99101
}
100102

101103
public async getVideoForSession(request: Request, response: Response, next: NextFunction) {

src/app/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import bodyParser from "body-parser";
33
import * as path from "path";
44
const cors = require("cors");
55
import { registerRoutes } from "./routes";
6+
import { Config } from "../config";
67

7-
function getRouter({ config }: { config: any }) {
8+
function getRouter({ config, dependencies }: { config: Config; dependencies: Record<string, any> }) {
89
let router = express.Router();
910
let apiRouter = express.Router();
1011
router.use(bodyParser.json());
@@ -23,7 +24,7 @@ function getRouter({ config }: { config: any }) {
2324
});
2425
});
2526

26-
registerRoutes(apiRouter, config);
27+
registerRoutes(apiRouter, config, dependencies);
2728

2829
router.use("/api", apiRouter);
2930
router.get("*", async (req: express.Request, res: express.Response, next: express.NextFunction) => {

src/app/routes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { Router } from "express";
2+
import { Config } from "../config";
23
import { IExpressController } from "../interfaces/express-controller";
34
import * as apiControllers from "./controllers/index";
45

5-
export let registerRoutes = (apiRouter: Router, config: any) => {
6+
export let registerRoutes = (apiRouter: Router, config: Config, dependencies: any) => {
67
let controllers: [string, IExpressController][] = [
78
["/sessions", new apiControllers.SessionController()],
89
["/builds", new apiControllers.BuildController()],
910
["/projects", new apiControllers.ProjectController()],
11+
["/debug", new apiControllers.DebugController(dependencies.debugEventEmitter)],
1012
];
1113

1214
for (let [path, controller] of controllers) {

src/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import * as os from "os";
22
import * as path from "path";
33
let basePath = path.join(os.homedir(), ".cache", "appium-dashboard-plugin");
44

5+
export interface Config {
6+
cacheDir: string;
7+
databasePath: string;
8+
videoSavePath: string;
9+
screenshotSavePath: string;
10+
logFilePath: string;
11+
takeScreenshotsFor: Array<string>;
12+
}
13+
514
export let config = {
615
cacheDir: basePath,
716
databasePath: `${basePath}`,

0 commit comments

Comments
 (0)