sum*_*mit 3 javascript selenium automation webdriver promise
我正在尝试使用 selenium web driver 和 node js 自动化几个页面。我能够登录,但登录后我想使用由网络驱动程序启动的相同会话,以便我可以在会话保护页面上进行自动测试。这是我的尝试
async function login(){
Let d = await new Builder()
.forBrowser('chrome')
.build();
await d.get('https://demo.textdomain.com/')
await d.findElement(By.id('username')).sendKeys('admin ')
await d.findElement(By.id('password')).sendKeys('admin');
await d.findElement(By.css('button[type="submit"]')).click();
d.getPageSource().then(function(content) {
if(content.indexOf('Welcome text') !==-1 ) {
console.log('Test passed');
console.log('landing page');
d.get('https://demo.textdomain.com/landingpage') //this is still going to login page as i cannot use the previous session
} else {
console.log('Test failed');
return false;
}
//driver.quit();
});
}
login();
Run Code Online (Sandbox Code Playgroud)
我登录后不小心丢弃了浏览器。
从SQA StackExchange上的一个类似问题,您可以存储和恢复当前会话的 cookie:
使用 JavaScript:
// Storing cookies:
driver.manage().getCookies().then(function (cookies) {
allCookies = cookies;
});
// Restoring cookies:
for (var key in allCookies) {
driver.manage().addCookie(key, allCookies[key]);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2449 次 |
| 最近记录: |