diff --git a/app_behat_runtime.js b/app_behat_runtime.js index 56fdbc3b3..182e5c185 100644 --- a/app_behat_runtime.js +++ b/app_behat_runtime.js @@ -476,6 +476,23 @@ return 'OK'; }; + /** + * Get main navigation controller. + * + * @return {Object} main navigation controller. + */ + var getNavCtrl = function() { + var mainNav = window.appProvider.appCtrl.getRootNavs()[0].getActiveChildNav(); + if (mainNav && mainNav.tabsIds.length && mainNav.firstSelectedTab) { + var tabPos = mainNav.tabsIds.indexOf(mainNav.firstSelectedTab); + if (tabPos !== -1 && mainNav._tabs && mainNav._tabs.length > tabPos) { + return mainNav._tabs[tabPos]; + } + } + // Fallback to return main nav - this will work but will overlay current tab. + return window.appProvider.appCtrl.getRootNavs()[0]; + }; + /** * Function to press arbitrary item based on its text or Aria label. * @@ -493,9 +510,13 @@ return 'ERROR: ' + error.message; } - // Simulate a mouse click on the button. - found.scrollIntoView(); + var mainContent = getNavCtrl().getActive()._cntDir; var rect = found.getBoundingClientRect(); + + // Scroll the item into view. + mainContent.scrollTo(rect.x, rect.y); + + // Simulate a mouse click on the button. var eventOptions = {clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2, bubbles: true, view: window, cancelable: true}; setTimeout(function() {