selenium-webdriver npm 检测成功 link 点击
selenium-webdriver npm detect successful link click
是否有可靠的方法来检测 link 点击到未知页面 selenium-webdriver npm 是否成功?
我需要能够在我的网站上测试简单的页面加载,并检查出站 link 到未知页面的加载是否正常。我正在使用的网站是一个假期出租网站,在酒店自己的页面上显示 link(因此目标 link 的内容将完全未知),我找不到任何可靠的检查方法如果酒店网站加载或不使用硒。
这是我到目前为止的测试:
//1 load up the url
driver.get( testConfig.url + '/britain/england/cornwall/hotel88').then(function(){
//2 get current page html title
var title = driver.findElement(By.css('title'));
title.getInnerHtml().then(function(html) {
var controlTestTitle = html;
//3 now move onto the owners link
driver.findElement(By.css('.details-web')).click().then(function(){
driver.wait(function(){
return driver.isElementPresent(By.css("title"));
}, testConfig.timeout).then(function(){
var title = driver.findElement(By.css('title'));
title.getInnerHtml().then(function(html) {
//check that this title is not the same
if( html != controlTestTitle ){
if (callback) {
callback(callback);
}
} else {
throw 'the page title did not change when moving onto the owners website';
}
});
});
});
});
});
上面的代码只是检查目标页面的 html 标题是否与原来的标题不一样..但是当测试运行时我没有看到酒店的网站实际加载所以我不是有信心测试是否真的成功。
我确实找到了这个 site trying 来解释它,但是代码是 java 我不知道..加上(你可能从这个 [=31= 的性质中看出) ]) 我对硒很陌生...
根据您的评论,以及您希望使用 selenium 完成此任务:
您可以做的是,在页面上找到至少 1 个点击 link 后会出现的元素。
单击 link 后,只需验证您找到的元素是否存在于页面上。如果不是,则表示页面未正确加载。
是否有可靠的方法来检测 link 点击到未知页面 selenium-webdriver npm 是否成功?
我需要能够在我的网站上测试简单的页面加载,并检查出站 link 到未知页面的加载是否正常。我正在使用的网站是一个假期出租网站,在酒店自己的页面上显示 link(因此目标 link 的内容将完全未知),我找不到任何可靠的检查方法如果酒店网站加载或不使用硒。
这是我到目前为止的测试:
//1 load up the url
driver.get( testConfig.url + '/britain/england/cornwall/hotel88').then(function(){
//2 get current page html title
var title = driver.findElement(By.css('title'));
title.getInnerHtml().then(function(html) {
var controlTestTitle = html;
//3 now move onto the owners link
driver.findElement(By.css('.details-web')).click().then(function(){
driver.wait(function(){
return driver.isElementPresent(By.css("title"));
}, testConfig.timeout).then(function(){
var title = driver.findElement(By.css('title'));
title.getInnerHtml().then(function(html) {
//check that this title is not the same
if( html != controlTestTitle ){
if (callback) {
callback(callback);
}
} else {
throw 'the page title did not change when moving onto the owners website';
}
});
});
});
});
});
上面的代码只是检查目标页面的 html 标题是否与原来的标题不一样..但是当测试运行时我没有看到酒店的网站实际加载所以我不是有信心测试是否真的成功。
我确实找到了这个 site trying 来解释它,但是代码是 java 我不知道..加上(你可能从这个 [=31= 的性质中看出) ]) 我对硒很陌生...
根据您的评论,以及您希望使用 selenium 完成此任务:
您可以做的是,在页面上找到至少 1 个点击 link 后会出现的元素。
单击 link 后,只需验证您找到的元素是否存在于页面上。如果不是,则表示页面未正确加载。