Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test scroll position with Karma, PhantomJS, Jasmine

I'm using Karma with Jasmine configured with the PhantomJS browser as detailed in browser section of Karma's config docs.

I'm testing a scroll behavior in the page by inspecting the $('body,html').scrollTop() value.

This works fine in Chrome. However, in PhantomJS the window size seems to be growing to be the size of the document. From their docs, working with viewport and scrollPosition requires direct phantomJS WebPage API usage.

Is there a way in Karma spec scripts to access the PhantomJS page object?

like image 309
jfroom Avatar asked Oct 22 '13 02:10

jfroom


1 Answers

A Karma contributor basically says in this this Github Issue to not use Karma for integration-level tests that would require dealing with the page variable.

vojtajina commented 3 months ago

You can't access page variable - the Angular scenario runner tests run IN THE BROWSER and there is no page variable.

The page variable is available in the phantomjs script (that you write to control the phantomjs browser). If you wanna use PhantomJS and its DSL for writing high level tests, just use PhantomJS without Angular scenario runner.

vojtajina commented 3 months ago

Nope, just use PhantomJS without Karma. Karma is for unit testing.

like image 57
queuebit Avatar answered Oct 04 '22 20:10

queuebit