I have a responsive website I need to test. If the website goes to the window size of a Tablet, I want the test to check if there is a horizontal scrollbar. According to the design they can never be present on a tablet.
Does anyone have a piece of pseudo-code to assert the presence of a horizontal scrollbar using Selenium Webdriver Java Cucumber?
You can test this with javascriptExecutor
:
Vertical scrollbar:
boolean scrollBarPresent = ((JavascriptExecutor)driver).executeScript("return document.documentElement.scrollHeight>document.documentElement.clientHeight;");
Horizontal scrollbar:
boolean scrollBarPresent = ((JavascriptExecutor)driver).executeScript("return document.documentElement.scrollWidth>document.documentElement.clientWidth;");