selenium

'use strict';

// 使用包的引入
const {Builder, By, Key, until,promise} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
const common = require('./lib/common.js');
var data = common.getJson('./test2/t.json');

promise.USE_PROMISE_MANAGER = false;
//
var expect = require('chai').expect;

// 这里可以采用下面的方式来构建(WebDriver)FirefoxDriver实例:(当默认方式打不开浏览器时)
describe('baidu test Search', function() {
let profile = new firefox.Profile('C:\Users\****\AppData\Roaming\Mozilla\Firefox\Profiles\s6lckcba.default');
let options = new firefox.Options().setProfile(profile);
let driver = new Builder().forBrowser('firefox').setFirefoxOptions(options).build();

// 分开执行(第一步)
describe('1', function () {
before(async function() {
common.getGolfError(true);
common.getPhpError(true);
// let profile = await new firefox.Profile("XXX");

await driver.get('XXX.html');

await driver.wait(until.elementLocated(By.id('day')));
await driver.findElement(By.id('day')).click();//

await driver.wait(until.elementLocated(By.xpath(data.day)));
await driver.findElement(By.xpath(data.day)).click();
// driver.sleep(8);
await driver.wait(until.elementLocated(By.id(data.area)));
await driver.findElement(By.id(data.area)).click();
//await driver.findElement(By.id('search_c_name_submit2')).click();

});

beforeEach(async function() {

});


afterEach(async function() {
// await driver.quit();
});


after(async function() {
// await driver.quit();
});


// after(async function () {

// await common.getGolfError(false, function (golf_log_txt) {
// console.log(golf_log_txt);
// });

// await common.getPhpError(false, function (php_log_txt) {
// console.log(php_log_txt);
// });
// // mail
// await common.getMail(false, function (mail_txt) {
// console.log(mail_txt);
// });
// // await driver.quit();
// });

// 校验当前url(当前)
// it('url test', async function() {
// let url = await driver.getCurrentUrl();
// expect(url).to.be.not.equal('www.baidud.com');
// });
//校验数值
it('input test', async function() {
await driver.wait(until.elementLocated(By.xpath('   ')));
var day = await driver.findElement(By.xpath('    ')).getAttribute('value');
expect(day).to.be.equal('   ');
await console.log(day);
});
});

//

describe('2', function () {

原文地址:https://www.cnblogs.com/luxia/p/10117971.html