theintern/visual-plugin

how to pass values from one command to another for window resizing?

thedewpoint opened this issue · 3 comments

I'm using the visual plugin with leadfoot in order to take some more dynamic screenshots. One thing I'd like to do is take full screen screenshots. In order to do this I have manually calculated the scrollheight and scrollwidth of the page and hardcoded it into the helpers.resizeWindow function before screenshotting. This has worked perfectly, but I'd like the values to be dynamic so I can reuse this configuration. I have tried calculating the scrollheight and scrollwidth dynamically using the execute command, but am struggling to pass the return values to the resize command correctly. Any advice is greatly appreciated.

Thank you

registerSuite('homepage', {
	'homepage'() {
            return this.remote.get('myurl')
            .setWindowPosition(0,0)
            .maximizeWindow()
            .execute(() => [document.documentElement.scrollWidth, document.documentElement.scrollHeight])
            .then(([width, height]) => {
               return helpers.resizeWindow(width, height)
            })
			.takeScreenshot()
			.then(
				assertVisuals(this, {
                    missingBaseline: 'snapshot',
                    regenerateBaselines: true
				})
			);
	}
});

Closing in favor of theintern/leadfoot#171

I was actually able to solve this by doing 2 things. I removed the helper.resizeWindow and used the regular command.resizeWindow, and instead of embedding it within the callback function, i just placed it there without the curly braces and without a return statement. I'm unsure why this syntax works and the other did not.

registerSuite('homepage', {
	'homepage'() {
            return this.remote.get('mypage')
            .setWindowPosition(0,0)
            .maximizeWindow()
            .execute(() => [document.documentElement.scrollWidth, document.documentElement.scrollHeight])
            .then(([width, height]) => this.remote.setWindowSize(width, height))
            .takeScreenshot()
			.then(
				assertVisuals(this, {
                    missingBaseline: 'snapshot',
                    regenerateBaselines: true
				})
			);
	}
});

The issue is likely not the syntax, as these two are the same:

.then(([width, height]) => this.remote.setWindowSize(width, height))

and

.then(([width, height]) => { return this.remote.setWindowSize(width, height)); })

The real difference is probably in how your resizeWindow helper is implemented vs setWindowSize.