Skip to content

Commit

Permalink
adding api endpoint for performing command
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtarsi committed Dec 1, 2023
1 parent 810ff2b commit f09c103
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/selenium-ide/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seleniumhq/selenium-ide",
"version": "4.0.0-alpha.58",
"version": "4.0.0-alpha.59",
"private": true,
"description": "Selenium IDE electron app",
"author": "Todd <[email protected]>",
Expand Down Expand Up @@ -105,7 +105,7 @@
"@seleniumhq/code-export-python-pytest": "^4.0.0-alpha.2",
"@seleniumhq/code-export-ruby-rspec": "^4.0.0-alpha.1",
"@seleniumhq/get-driver": "^4.0.0-alpha.1",
"@seleniumhq/side-api": "^4.0.0-alpha.36",
"@seleniumhq/side-api": "^4.0.0-alpha.37",
"@seleniumhq/side-model": "^4.0.0-alpha.4",
"@seleniumhq/side-runtime": "^4.0.0-alpha.31",
"dnd-core": "^16.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CommandShape, hasID } from '@seleniumhq/side-api'
import {
Playback,
PlaybackEvents,
PlaybackEventShapes,
Variables,
} from '@seleniumhq/side-runtime'
import { WebDriverExecutorHooks } from '@seleniumhq/side-runtime/src/webdriver'
import { hasID } from '@seleniumhq/side-api/dist/helpers/hasID'
import { randomUUID } from 'crypto'
import { session } from 'electron'
import { Session } from 'main/types'
Expand Down Expand Up @@ -95,6 +95,23 @@ export default class PlaybackController extends BaseController {
this.playbacks.forEach((playback) => playback.pause())
}

async performCommand(
command: Omit<CommandShape, 'id'>
) {
const playback = new Playback({
baseUrl: this.session.projects.project.url,
executor: await this.session.driver.build({}),
getTestByName: (name: string) => this.session.tests.getByName(name),
logger: console,
variables: new Variables(),
options: {
delay: this.session.projects.project.delay || 0,
},
})
await playback.playSingleCommand({ ...command, id: '-1' })
await playback.cleanup()
}

async stop() {
if (this.isPlaying) {
await this.pause()
Expand Down
2 changes: 1 addition & 1 deletion packages/side-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seleniumhq/side-api",
"version": "4.0.0-alpha.36",
"version": "4.0.0-alpha.37",
"private": false,
"description": "Selenium IDE API command shapes and such",
"author": "Todd Tarsi <[email protected]>",
Expand Down
4 changes: 4 additions & 0 deletions packages/side-api/src/commands/playback/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Shape as OnBeforeAll } from './onBeforeAll'
import type { Shape as OnPlayUpdate } from './onPlayUpdate'
import type { Shape as OnStepUpdate } from './onStepUpdate'
import type { Shape as Pause } from './pause'
import type { Shape as PerformCommand } from './performCommand'
import type { Shape as Play } from './play'
import type { Shape as PlaySuite } from './playSuite'
import type { Shape as Resume } from './resume'
Expand All @@ -17,6 +18,7 @@ import * as onBeforeAll from './onBeforeAll'
import * as onPlayUpdate from './onPlayUpdate'
import * as onStepUpdate from './onStepUpdate'
import * as pause from './pause'
import * as performCommand from './performCommand'
import * as play from './play'
import * as playSuite from './playSuite'
import * as resume from './resume'
Expand All @@ -30,6 +32,7 @@ export const commands = {
onPlayUpdate,
onStepUpdate,
pause,
performCommand,
play,
playSuite,
resume,
Expand All @@ -47,6 +50,7 @@ export type Shape = {
onPlayUpdate: OnPlayUpdate
onStepUpdate: OnStepUpdate
pause: Pause
performCommand: PerformCommand
play: Play
playSuite: PlaySuite
resume: Resume
Expand Down
6 changes: 6 additions & 0 deletions packages/side-api/src/commands/playback/performCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { CommandShape } from '@seleniumhq/side-model'

/**
* Attempts to execute a command supplied via API directly
*/
export type Shape = (cmd: Omit<CommandShape, 'id'>) => Promise<boolean>
4 changes: 2 additions & 2 deletions packages/side-example-suite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seleniumhq/side-example-suite",
"version": "4.0.0-alpha.4",
"version": "4.0.0-alpha.5",
"private": true,
"description": "Selenium IDE example suite, with tests, plugin, and export format",
"author": "Todd <[email protected]>",
Expand All @@ -21,7 +21,7 @@
"@seleniumhq/code-export-python-pytest": "4.0.0-alpha.2"
},
"devDependencies": {
"@seleniumhq/side-api": "^4.0.0-alpha.33"
"@seleniumhq/side-api": "^4.0.0-alpha.37"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

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

0 comments on commit f09c103

Please sign in to comment.