我正在使用Selenium
,WebDriverJS
和Jasmine
为我的网页编写和端到端测试。在这部分代码中,我想检查当单击一个按钮时,窗口正确滚动到html
页面的顶部。这是我要检查的功能:
$(document).ready(function(){
//Check to see if the window is top if not then display button
$(window).scroll(function(){
if ($(this).scrollTop() > 800) {
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
//Click event to scroll to top
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},600);
return false;
});
});
这是我为测试而编写的测试:
it('should enable to click on the logo to get back to the top of the page', function() {
// Header's logo should not be displayed in the page
this.driver.sleep(this.driver.executeScript('onload'));
var logoHeader = this.driver.findElement(webdriver.By.css('.scrollToTop img'));
logoHeader.isDisplayed().then(function(present) {
expect(present).not.toBe(true);
});
// Header's logo should be displayed in the page when window is scrolled
this.driver.executeScript('arguments[0].scrollIntoView(true)', logoHeader);
logoHeader.isDisplayed();
// When clicking on the button, page should be scrolled up to the beginning
logoHeader.click();
this.driver.manage().window().getPosition().then(function(position) {
expect(position).toBe({ x: 0, y: 0});
});
});
但是当我运行测试时,我收到以下错误:
Message:
Expected Object({ x: 0, y: 23 }) to be Object({ x: 0, y: 0 }).
您知道我的代码有什么问题吗?或者您有一个类似示例的教程?
提前感谢您的回复!