我是使用节点js进行硒单元测试的新手,我已经创建了用于登录的常规脚本,当我运行命令npx mocha test.js
时,它会打开浏览器,但不会运行我的URL和登录操作,有人可以看一下我的代码并帮助我解决此问题吗?
const {Builder, By, Key, until} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
const chrome = require('selenium-webdriver/chrome');
const screen = {
width: 640,
height: 480
};
const test = async function() {
let driver = await new Builder().forBrowser('firefox').setFirefoxOptions(new firefox.Options().windowSize(screen)).build();
try {
await driver.get('http://localhost:4200/login');
await driver.findElement(By.id('mat-input-0')).sendKeys('root_admin');
await driver.findElement(By.id('mat-input-1')).sendKeys('Admin123');
await driver.sleep(5000);
const button = await driver.findElement(By.className('mt-3'));
await button.click();
await driver.sleep(2000);
} finally {
await driver.quit();
}
}
test();