我正在使用Selenium-Webdriver,Mocha和Chai对我公司的应用程序的FrontEnd进行端到端测试。当有错误时测试运行(幸运的是通常成功)时,Expect代码块中的自定义描述未显示。
我尝试使用Google搜索来寻找一些答案,但是找不到适合自己所做的解释。我觉得这是Chai的一部分,它“应该”可以工作,但是我不知道为什么不可以。
it('Fills in the required fields and creates New Reseller Company', async function(){
const companyDescription = 'This is a test description for a random test company blah blah blah';
const companyAddress = '777 Lucky Lane';
const companyCity = 'Anonitopia';
const companyState = 'Internet';
const companyZip = '99999';
const companyNameElem = await driver.findElement(By.xpath("//div[contains(@class, 'input-container')]/input[@label='Company Name']"));
await util.sendKeys(companyNameElem, companyName);
const companyDescriptionElem = await driver.findElement(By.xpath("//textarea"));
await companyDescriptionElem.sendKeys(companyDescription);
const companyTypeElem = await driver.findElement(By.xpath("//select"));
await companyTypeElem.click();
await driver.wait(until.elementLocated(By.xpath("//select/option"), 10000));
const companyTypeSelectElem = await driver.findElement(By.xpath("//select/option[@value='1']"));
await companyTypeSelectElem.click();
const companyImageElem = await driver.findElement(By.xpath("//div/input[@type='file']"));
await companyImageElem.sendKeys(companyImage);
await driver.wait(until.elementLocated(By.xpath("//img[@class='image-preview']"), 10000));
const addressElem = await driver.findElement(By.xpath("//div[contains(@class, 'input-container')]/input[@label='Address']"));
await addressElem.sendKeys(companyAddress);
const cityElem = await driver.findElement(By.xpath("//div[contains(@class, 'input-container')]/input[@label='City']"));
await cityElem.sendKeys(companyCity);
const stateElem = await driver.findElement(By.xpath("//div[contains(@class, 'input-container')]/input[@label='State']"));
await stateElem.sendKeys(companyState);
const zipElem = await driver.findElement(By.xpath("//div[contains(@class, 'input-container')]/input[@label='Zip Code']"));
await zipElem.sendKeys(companyZip);
const submitButtonElem = await driver.findElement(By.xpath("//button[contains(text(),'Submit')]"));
await submitButtonElem.click();
await driver.wait(until.elementLocated(By.xpath("//h3[contains(text(),'Company Actions')]"), 10000));
await driver.wait(until.elementLocated(By.xpath("//p[@class='company-name']"), 10000));
const companySuccessElem = await driver.findElement(By.xpath("//p[@class='company-name'][contains(text(),'"+companyName+"')]"));
let companySuccess = await companySuccessElem.isDisplayed();
await expect(companySuccess, 'Failed to Create New Company').to.be.true;
});
尽管所附加的代码部分具有相当多的故障预防能力,但它实际上是其中不包含有关我所工作的公司和我们所从事的工作类型的任何信息的部分之一。但是,如果该部分失败,则根据我对期望工作原理的理解,如果测试失败,则应显示“无法创建新公司”。但是,如果测试失败,则仅输出it语句的内容:X)填写必填字段并创建新经销商公司(其中X =一个数字,描述测试脚本/套件中失败次数的顺序)。
我在做什么错?感谢您的指导!