【发布时间】:2021-02-13 15:12:37
【问题描述】:
我正在自动测试预订航班。在主页上输入航班凭据,单击提交按钮,浏览器会转到包含搜索结果的页面。
const EC = protractor.ExpectedConditions;
describe('Delta airlines booking sample', function () {
const toAirportName = element(by.id('toAirportName'));
const toAirportNameSearchInput = element(by.id('search_input'));
const berlinCityAirport = element(by.css('li.airport-list:nth-child(1)'));
const tripTypeSelector = element(by.id('selectTripType-val'));
const tripTypeOneWay = element(by.id('ui-list-selectTripType1'));
const departmentDateLabel = element(by.id('calDepartLabelCont'));
const departureDate = element(by.xpath("//a[@aria-label='5 November 2020, Thursday']"))
const departureDatePickerDone = element(by.xpath("//button[@aria-label='done']"));
const buttonBookSubmit = element(by.id('btn-book-submit'));
const errorMessage = element(by.id('advance-search-global-err-msg'));
beforeEach(function () {
browser.get('https://www.delta.com/');
browser.manage().window().maximize();
});
it('should have to airport destination field clickable', () => {
toAirportName.click();
toAirportNameSearchInput.sendKeys('Berlin \n');
berlinCityAirport.getText().then(text => {
text.includes('BER') ? berlinCityAirport.click() : console.log('Wrong search result');
});
tripTypeSelector.click();
tripTypeOneWay.click();
departmentDateLabel.click();
departureDate.click();
departureDatePickerDone.click();
buttonBookSubmit.click();
browser.wait(EC.presenceOf(errorMessage), 10000);
expect(errorMessage.getText()).toEqual("Uh-oh! We're sorry, but no results were found for your search.We have adjusted our flight schedules and some of our flights only operate seasonally or on select days of the week.Try changing your cities or dates for additional results.#101763R");
});
});
如您所见 - 我没有使用任何页面对象。我试图从 searchresult 页面获取错误代码,因为它是主页的一部分(很天真,对吧?)。由于新页面的 URL 包含 ?cacheKeySuffix=....,因此每次运行测试时都会更改它。
如何从搜索结果页面获取数据?
如何
【问题讨论】:
-
你想获取什么数据?你为什么提到网址?这对这个测试很重要吗?错误信息是否实际显示?你必须给我们一些更多的细节。至少对我来说,目前还不清楚这里出了什么问题。测试失败了吗?
标签: javascript node.js protractor ui-automation