Skip to content

Commit

Permalink
264 sim fix frontend e2e tests (#271)
Browse files Browse the repository at this point in the history
* fix: fixed e2e tests to create required validators before run conracts

* feat: updated tests and added page factory and driver settings

* fix: added common create validator util in settings page
  • Loading branch information
bradleySuira authored Jul 17, 2024
1 parent 4fd2663 commit 3bc136d
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 15 deletions.
12 changes: 9 additions & 3 deletions frontend/test/e2e/ContractExampleStorage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { WebDriver, By, until } from 'selenium-webdriver'
import { ContractsPage } from '../pages/ContractsPage.js'
import { RunDebugPage } from '../pages/RunDebugPage.js'
import { SettingsPage } from '../pages/SettingsPage.js'
import { before, describe, after, it } from 'node:test'
import { expect } from 'chai'
import { getDriver } from '../utils/driver.js'

let driver: WebDriver
let contractsPage: ContractsPage
let runDebugPage: RunDebugPage
let settingsPage: SettingsPage

describe('Contract Example Storage', () => {
before(async () => {
driver = await getDriver()
await driver.manage().setTimeouts({ implicit: 10000 })
contractsPage = new ContractsPage(driver)
runDebugPage = new RunDebugPage(driver)
settingsPage = new SettingsPage(driver)

await contractsPage.navigate()
await contractsPage.waitUntilVisible()
await contractsPage.skipTutorial()
await settingsPage.navigate()
await settingsPage.createValidatorIfRequired()
})

it('should open Storage example contract', async () => {
await contractsPage.navigate()
await contractsPage.waitUntilVisible()
await contractsPage.skipTutorial()
await contractsPage.openContract('storage.gpy')
const tabs = await driver.findElements(By.xpath("//div[contains(@class, 'contract-item')]"))
expect(tabs.length, 'Number of tabs should be 2').equal(2)
Expand Down Expand Up @@ -84,7 +91,6 @@ describe('Contract Example Storage', () => {
})

it('should call get_storage state', async () => {

const stateBtn = await driver.wait(
until.elementLocated(By.xpath("//button[text()='get_storage']")),
25000
Expand Down
11 changes: 9 additions & 2 deletions frontend/test/e2e/ContractExampleWizardOfCoin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { WebDriver, By, until } from 'selenium-webdriver'
import { ContractsPage } from '../pages/ContractsPage.js'
import { RunDebugPage } from '../pages/RunDebugPage.js'
import { SettingsPage } from '../pages/SettingsPage.js'
import { before, describe, after, it } from 'node:test'
import { expect } from 'chai'
import { getDriver } from '../utils/driver.js'

let driver: WebDriver
let contractsPage: ContractsPage
let runDebugPage: RunDebugPage
let settingsPage: SettingsPage

describe('Contract Example WizardOfCoin', () => {
before(async () => {
driver = await getDriver()
await driver.manage().setTimeouts({ implicit: 10000 })
contractsPage = new ContractsPage(driver)
runDebugPage = new RunDebugPage(driver)
settingsPage = new SettingsPage(driver)

await contractsPage.navigate()
await contractsPage.waitUntilVisible()
await contractsPage.skipTutorial()
await settingsPage.navigate()
await settingsPage.createValidatorIfRequired()
})

it('should open WizardOfCoin example contract', async () => {
await contractsPage.navigate()
await contractsPage.waitUntilVisible()
await contractsPage.skipTutorial()
await contractsPage.openContract('wizard_of_coin.gpy')
const tabs = await driver.findElements(By.xpath("//div[contains(@class, 'contract-item')]"))
expect(tabs.length, 'Number of tabs should be 2').equal(2)
Expand Down
1 change: 0 additions & 1 deletion frontend/test/e2e/CreateNodeValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ let contractsPage: ContractsPage
describe('Settings - Create Node Validator', () => {
before(async () => {
driver = await getDriver()
await driver.manage().setTimeouts({ implicit: 10000 })
settingsPage = new SettingsPage(driver)
contractsPage = new ContractsPage(driver)
})
Expand Down
1 change: 0 additions & 1 deletion frontend/test/e2e/DeleteNodeValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ let contractsPage: ContractsPage
describe('Settings - Delete Node Validator', () => {
before(async () => {
driver = await getDriver()
await driver.manage().setTimeouts({ implicit: 10000 })
settingsPage = new SettingsPage(driver)
contractsPage = new ContractsPage(driver)
})
Expand Down
2 changes: 0 additions & 2 deletions frontend/test/e2e/Tutorial.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { WebDriver, By, until } from 'selenium-webdriver'

import { TutorialPage } from '../pages/TutorialPage.js'
import { ContractsPage } from '../pages/ContractsPage.js'
import { before, describe, after, it } from 'node:test'
import { expect } from 'chai'
import { getDriver } from '../utils/driver.js'
Expand Down Expand Up @@ -58,7 +57,6 @@ async function validateTutorialStep({
describe('Tutorial - Run all tutorial steps', () => {
before(async () => {
driver = await getDriver()
await driver.manage().setTimeouts({ implicit: 10000 })
tutorialPage = new TutorialPage(driver)
})

Expand Down
3 changes: 1 addition & 2 deletions frontend/test/e2e/UpdateNodeValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ let contractsPage: ContractsPage
describe('Settings - Update Node Validator', () => {
before(async () => {
driver = await getDriver()
await driver.manage().setTimeouts({ implicit: 10000 })
settingsPage = new SettingsPage(driver)
contractsPage = new ContractsPage(driver)
})
Expand Down Expand Up @@ -67,7 +66,7 @@ describe('Settings - Update Node Validator', () => {
// call save validator button
await updateValidatorBtn.click()

driver.sleep(5000)
driver.sleep(10000)
const validators = await settingsPage.getValidatorsElements()
const provider = await validators[0].findElement(By.xpath("//span[@data-testid = 'validator-item-provider']"))
const model = await validators[0].findElement(By.xpath("//span[@data-testid = 'validator-item-model']"))
Expand Down
17 changes: 17 additions & 0 deletions frontend/test/pages/SettingsPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { By, Locator, WebElement, until, Select } from 'selenium-webdriver'
import { BasePage } from './BasePage'
import { expect } from 'chai'

export class SettingsPage extends BasePage {
override baseurl = 'http://localhost:8080/simulator/settings'
Expand Down Expand Up @@ -52,4 +53,20 @@ export class SettingsPage extends BasePage {
await createValidatorBtn.click()
await this.driver.navigate().refresh()
}

async createValidatorIfRequired() {
const initialValidators = await this.getValidatorsElements()
if (initialValidators.length < 1) {
await this.createValidator({
provider: 'heuristai',
model: 'mistralai/mixtral-8x7b-instruct',
stake: 7
})
const existingValidators = await this.getValidatorsElements()
expect(
existingValidators.length,
'number of validators should be greather than old validators list'
).be.greaterThan(initialValidators.length)
}
}
}
10 changes: 6 additions & 4 deletions frontend/test/utils/driver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Builder, Browser, WebDriver } from 'selenium-webdriver';
import { Builder, Browser, WebDriver } from 'selenium-webdriver'

export async function getDriver():Promise<WebDriver> {
return new Builder().forBrowser(Browser.CHROME).build();
}
export async function getDriver(): Promise<WebDriver> {
const driver = await new Builder().forBrowser(Browser.CHROME).build()
await driver.manage().setTimeouts({ implicit: 10000 })
return driver
}
28 changes: 28 additions & 0 deletions frontend/test/utils/pages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ContractsPage } from '../pages/ContractsPage.js'
import { RunDebugPage } from '../pages/RunDebugPage.js'
import { SettingsPage } from '../pages/SettingsPage.js'
import { TutorialPage } from '../pages/TutorialPage.js'
import { WebDriver } from 'selenium-webdriver'


export class PageFactory {
private _driver: WebDriver

constructor(driver: WebDriver) {
this._driver = driver
}

getContractsPage() {
return new ContractsPage(this._driver)
}
getRunDebugPage() {
return new RunDebugPage(this._driver)
}
getSettingsPage() {
return new SettingsPage(this._driver)
}

getTutorialPage() {
return new TutorialPage(this._driver)
}
}

0 comments on commit 3bc136d

Please sign in to comment.