Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Add a slight wait to checking if element has class. Since updates happen
asynchronously now the puzzle solved class is not immediately available
on the body after a move is made.
  • Loading branch information
kflorence committed Jan 20, 2024
1 parent 8d189b2 commit 256993a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('chromedriver')
const chrome = require('selenium-webdriver/chrome')
const { Builder, By, until } = require('selenium-webdriver')
const { Builder, By, until, WebElementCondition } = require('selenium-webdriver')

class PuzzleFixture {
driver
Expand Down Expand Up @@ -58,7 +58,7 @@ class PuzzleFixture {
}

async isSolved () {
return hasClass(this.elements.body, 'puzzle-solved')
return elementHasClass(this.elements.body, 'puzzle-solved')
}

async selectModifier (name) {
Expand All @@ -74,9 +74,10 @@ class PuzzleFixture {
static baseUrl = 'http://localhost:1234'
}

async function hasClass (element, name) {
const classes = (await element.getAttribute('class')).split(' ')
return classes.some((className) => name === className)
function elementHasClass (element, name) {
return new WebElementCondition('until element has class', function () {
return element.getAttribute('class').then((classes) => classes.split(' ').some((className) => name === className))
})
}

module.exports = {
Expand Down

0 comments on commit 256993a

Please sign in to comment.