let driver, testVars, exiserror = "first";
before(function(){
let self = this;
driver = self.driver;
testVars = self.testVars;
});
it('url: https://{{DUT1_MGT_IP}}', async function(){
await driver.url(_(`https://{{DUT1_MGT_IP}}`));
});
it('waitBody: ', async function(){
await driver.sleep(500).wait('body', 45000).html().then(function(code){
isPageError(code).should.be.false;
});
});
it('判断元素是否存在#username', async function(){
await driver.sleep(300).wait('#username', 2000).sleep(300).catch(function(error){exiserror = "notfirst";});
});
it('登录, 101, 22, 0', async function(){
if (exiserror == "first" ){
await driver.sleep(300).wait('#username', 30000).sleep(300).mouseMove().click(0);
await driver.sendKeys('ns25000');
await driver.sleep(300).wait('#password', 30000).sleep(300).mouseMove().click(0);
await driver.sendKeys('ns25000');
await driver.sleep(300).wait('#verificationCode', 30000).sleep(300).mouseMove().click(0);
await driver.sendKeys('8888');
await driver.sleep(300).wait('//button//span[text()="立即登录"]/..', 30000).sleep(300).mouseMove().click(0);
}
});
核心观点:
1、使用有一个标记变量,来判断语句的输入
2、使用catch方式返回变量,默认webdriver的话,找不到,回fail退出程序
使用其它异常捕捉方式应该也可以,没试过