Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #58 from EtherealEngine/9141-added-new-bot-tests
Browse files Browse the repository at this point in the history
Added automated test
  • Loading branch information
HexaField authored Nov 21, 2023
2 parents 7369afa + 2758251 commit 7156b86
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 0 deletions.
31 changes: 31 additions & 0 deletions e2e/dev/all-editor-action.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import assert from 'assert'
import { Vector3 } from 'three'
import { EtherealEngineBot } from 'ee-bot/src/bot/bot-class'
import { BotHooks } from 'ee-bot/src/enums/BotHooks'

const vector3 = new Vector3()

//const domain = process.env.APP_HOST
const domain = 'localhost:3000'
const locationName = 'apartment'
const sqrt2 = Math.sqrt(2)

describe('My Bot Tests', () => {
const bot = new EtherealEngineBot({ name: 'bot', headless:false, verbose: true })
before(async () => {
await bot.launchBrowser()
await bot.enterLocation(`https://${domain}/location/${locationName}`)
await bot.awaitHookPromise(BotHooks.LocationLoaded)
await bot.clickAllButtons()
})

after(async () => {
await bot.quit()
})

it('Can spawn in the world', async () => {
const pos = await bot.awaitHookPromise(BotHooks.GetPlayerPosition)
// assert(vector3.copy(pos).length() < sqrt2 * 2) // sqrt2 * 2 is the default size of our spawn area
})
})

39 changes: 39 additions & 0 deletions e2e/dev/alldirection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import assert from 'assert'
import { Vector3 } from 'three'
import { EtherealEngineBot } from 'ee-bot/src/bot/bot-class'
import { BotHooks } from 'ee-bot/src/enums/BotHooks'

//const vector3 = new Vector3()

//const domain = process.env.APP_HOST
const domain = 'localhost:3000'
const locationName = 'apartment'
const sqrt2 = Math.sqrt(2)

describe('My Bot Tests', () => {
const bot = new EtherealEngineBot({ name: 'bot', headless:false, verbose: true })
before(async () => {
await bot.launchBrowser()
await bot.enterLocation(`https://${domain}/location/${locationName}`)
await bot.awaitHookPromise(BotHooks.LocationLoaded)
await bot.moveBot('forward', 2000)
await bot.moveBot('backward',2000)
await bot.moveBot('left',2000)
await bot.moveBot('right',2000)
await bot.moveBot('jump',2000)
await bot.moveBot('up',2000)
await bot.moveBot('down',2000)
await bot.moveBot('arrowleft',1000)
await bot.moveBot('arrowright',1000)
})

after(async () => {
await bot.quit()
})

it('Can spawn in the world', async () => {
const pos = await bot.awaitHookPromise(BotHooks.GetPlayerPosition)
//assert(vector3.copy(pos).length() < sqrt2 * 2) // sqrt2 * 2 is the default size of our spawn area
})
})

31 changes: 31 additions & 0 deletions e2e/dev/emote.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import assert from 'assert'
import { Vector3 } from 'three'
import { EtherealEngineBot } from 'ee-bot/src/bot/bot-class'
import { BotHooks } from 'ee-bot/src/enums/BotHooks'

//const vector3 = new Vector3()

//const domain = process.env.APP_HOST
const domain = 'localhost:3000'
const locationName = 'apartment'
const sqrt2 = Math.sqrt(2)

describe('My Bot Tests', () => {
const bot = new EtherealEngineBot({ name: 'bot', headless:false, verbose: true })
before(async () => {
await bot.launchBrowser()
await bot.enterLocation(`https://${domain}/location/${locationName}`)
await bot.awaitHookPromise(BotHooks.LocationLoaded)
await bot.clickEmoteButtonAndSelectEmote()
})

after(async () => {
await bot.quit()
})

it('Can spawn in the world', async () => {
const pos = await bot.awaitHookPromise(BotHooks.GetPlayerPosition)
//assert(vector3.copy(pos).length() < sqrt2 * 2) // sqrt2 * 2 is the default size of our spawn area
})
})

31 changes: 31 additions & 0 deletions e2e/dev/moveforward.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import assert from 'assert'
import { Vector3 } from 'three'
import { EtherealEngineBot } from 'ee-bot/src/bot/bot-class'
import { BotHooks } from 'ee-bot/src/enums/BotHooks'

//const vector3 = new Vector3()

//const domain = process.env.APP_HOST
const domain = 'localhost:3000'
const locationName = 'apartment'
const sqrt2 = Math.sqrt(2)

describe('My Bot Tests', () => {
const bot = new EtherealEngineBot({ name: 'bot', headless:false, verbose: true })
before(async () => {
await bot.launchBrowser()
await bot.enterLocation(`https://${domain}/location/${locationName}`)
await bot.awaitHookPromise(BotHooks.LocationLoaded)
await bot.moveBot('forward',2000)
})

after(async () => {
await bot.quit()
})

it('Can spawn in the world', async () => {
const pos = await bot.awaitHookPromise(BotHooks.GetPlayerPosition)
//assert(vector3.copy(pos).length() < sqrt2 * 2) // sqrt2 * 2 is the default size of our spawn area
})
})

34 changes: 34 additions & 0 deletions e2e/dev/physics-triggers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import assert from 'assert'
import { Vector3 } from 'three'
import { EtherealEngineBot } from 'ee-bot/src/bot/bot-class'
import { BotHooks } from 'ee-bot/src/enums/BotHooks'
import { makeAdmin } from 'ee-bot/src/bot/utils/make-user-admin'

const vector3 = new Vector3()

//const domain = process.env.APP_HOST
const domain = 'localhost:3000'
const locationName = 'default'
const sqrt2 = Math.sqrt(2)

describe('My Bot Tests', () => {
const bot = new EtherealEngineBot({ name: 'bot', headless:false, verbose: true })
before(async () => {
await bot.launchBrowser()
//await bot.enterLocation(`https://${domain}`)
//await bot.awaitHookPromise(BotHooks.LocationLoaded)
await bot.enterEditor(`https://${domain}/studio/default-project/apartment`,`https://${domain}` )
await bot.physics_triggers()
await bot.enterLocation(`https://${domain}/location/${locationName}`)
await bot.awaitHookPromise(BotHooks.LocationLoaded)
await bot.moveBot('forward',2000)
})

after(async () => {
await bot.quit()
})

it('Can spawn in the world', async () => {
})
})

33 changes: 33 additions & 0 deletions e2e/dev/portal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from 'assert'
import { Vector3 } from 'three'
import { EtherealEngineBot } from 'ee-bot/src/bot/bot-class'
import { BotHooks } from 'ee-bot/src/enums/BotHooks'

const vector3 = new Vector3()

//const domain = process.env.APP_HOST
const domain = 'localhost:3000'
const locationName = 'apartment'
const sqrt2 = Math.sqrt(2)

describe('My Bot Tests', () => {
const bot = new EtherealEngineBot({ name: 'bot', headless:false, verbose: true })
before(async () => {
await bot.launchBrowser()
await bot.enterLocation(`https://${domain}/location/${locationName}`)
await bot.awaitHookPromise(BotHooks.LocationLoaded)
await bot.moveBot('forward',3000)
await bot.moveBot('left',2000)
await bot.moveBot('backward',4000)
})

after(async () => {
await bot.quit()
})

it('Can spawn in the world', async () => {
const pos = await bot.awaitHookPromise(BotHooks.GetPlayerPosition)
// assert(vector3.copy(pos).length() < sqrt2 * 2) // sqrt2 * 2 is the default size of our spawn area
})
})

53 changes: 53 additions & 0 deletions e2e/editor/xrui.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import assert from 'assert'
import { EtherealEngineBot } from 'ee-bot/src/bot/bot-class'
import { BotHooks } from 'ee-bot/src/enums/BotHooks'

import { delay } from '@etherealengine/engine/src/common/functions/delay'
import type { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
import { EngineState } from '@etherealengine/engine/src/ecs/classes/EngineState'

const domain = process.env.APP_HOST || 'localhost:3000'
const editorUrl = `https://${domain}/studio`

describe('Editor Scene Tests', () => {
const bot = new EtherealEngineBot({ name: 'bot', verbose: true, headless: false })
before(async () => {
await bot.launchBrowser()
await bot.enterEditor(`https://${domain}/studio/`,`https://${domain}`)
})

after(async () => {
await bot.quit()
})

it('should load scene', async () => {
// open root editor page
await bot.navigate(editorUrl)

// click on project
await bot.clickElementById('open-ee-development-test-suite')

// click on scene
await bot.page.waitForSelector(`[class^='_sceneContainer_1b1hs_126']`, { visible: true })
await bot.page.click(`[class^='_sceneContainer_1b1hs_126']`)

await delay(6000)

// assert scene has loaded
await bot.awaitHookPromise(BotHooks.SceneLoaded)

const serializedEngine = JSON.parse(await bot.runHook(BotHooks.SerializeEngine)) // as Engine
const engineState = serializedEngine.store.stateMap['engine'] as any as typeof EngineState._TYPE
assert.equal(serializedEngine.isEditor, true)
assert.equal(engineState.sceneLoaded, true)
})

// it.skip('should unload scene and load second scene', async () => {
// await bot.page.click('#rc-tabs-0-tab-scenePanel')
// await bot.page.click(`[class^='_sceneContainer']:nth-child(2)`)
// await bot.awaitHookPromise(BotHooks.SceneLoaded)
// const serializedEngine = JSON.parse(await bot.runHook(BotHooks.SerializeEngine)) as Engine
// assert.equal(serializedEngine.isEditor, true)
// assert.equal((serializedEngine.store.state['engine'] as any as ReturnType<typeof getEngineState>['value']).sceneLoaded, true)
// })
})

0 comments on commit 7156b86

Please sign in to comment.