Skip to content

Instantly share code, notes, and snippets.

@claustres
Created June 26, 2018 20:27
Show Gist options
  • Save claustres/d3c5a47d06428e029e5e4c5adc57ad84 to your computer and use it in GitHub Desktop.
Save claustres/d3c5a47d06428e029e5e4c5adc57ad84 to your computer and use it in GitHub Desktop.
Print client page model for TestCafé
import { Selector } from 'testcafe'
export class PrintApp {
constructor () {
this.baseLayerMenu = Selector('.basemaps')
this.overlayLayerMenu = Selector('.leaflet-control-layers')
this.fileInput = Selector('input').withAttribute('type', 'file')
this.printMenu = Selector('#leafletEasyPrint')
}
async checkNoError (test) {
const { error } = await test.getBrowserConsoleMessages()
await test.expect(error[0]).notOk()
}
async selectBaseLayer (test, layerName) {
let layerSelector = Selector('img').withAttribute('title', layerName)
await test
.click(this.baseLayerMenu)
.click(layerSelector)
// Since we have async data download wait a little bit
.wait(5000)
}
async selectOverlayLayer (test, layerName) {
// Checkbox is the sibling of the text
let layerSelector = Selector('span').withText(layerName).prevSibling()
await test
.hover(this.overlayLayerMenu)
.click(layerSelector)
// Since we have async data download wait a little bit
.wait(5000)
}
async addGeoJson (test, fileName) {
await test
.setFilesToUpload(this.fileInput, fileName)
// Since we have async data download wait a little bit
.wait(5000)
}
async setFullscreen (test) {
await test
.maximizeWindow()
// Since we have async data download wait a little bit
.wait(5000)
}
async print (test, format) {
let printButton = Selector('.easyPrintSizeMode').withAttribute('title', format)
await test
.click(this.printMenu)
.click(printButton)
// Wait for print
.wait(20000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment