我在菜单栏中有下拉菜单。当我测试下拉列表时,它工作正常。但是,当我点击下拉列表中的某个项目时,它不会显示与该项目相关的任何数据。
测试:
it('Add Patient', function(){
ptor = protractor.getInstance();
var dropdown = element.all(by.css('.dropdown')).get(3);
var toggle = dropdown.element(by.css('.dropdown-toggle'));
toggle.click();
toggle.click();
ptor.sleep(2000);
var list = dropdown.all(by.css('.dropdown-menu li'));
expect(list.get(1).getText()).toEqual('Patients');
var test = list.get(1);
test.click();
});
日志就像这样打印。
Dropdown Log***** { parentElementArrayFinder:
{ getWebElements: [Function],
actionResults_: undefined,
locator_: { using: 'css selector', value: '.dropdown' },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] },
elementArrayFinder_:
{ getWebElements: [Function],
actionResults_: undefined,
locator_: { using: 'css selector', value: '.dropdown' },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] }
Toggle Log******** { parentElementArrayFinder:
{ getWebElements: [Function],
actionResults_: undefined,
locator_: { using: 'css selector', value: '.dropdown-toggle' },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] },
elementArrayFinder_:
{ getWebElements: [Function],
actionResults_: undefined,
locator_: { using: 'css selector', value: '.dropdown-toggle' },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] }
List log***** { getWebElements: [Function],
actionResults_: undefined,
locator_: { using: 'css selector', value: '.dropdown-menu li' },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] }
Test log***** { parentElementArrayFinder:
{ getWebElements: [Function],
actionResults_: undefined,
locator_: { using: 'css selector', value: '.dropdown-menu li' },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] },
elementArrayFinder_:
{ getWebElements: [Function],
actionResults_: undefined,
locator_: { using: 'css selector', value: '.dropdown-menu li' },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] },
click: [Function],
sendKeys: [Function],
getTagName: [Function],
getCssValue: [Function],
getAttribute: [Function],
getText: [Function],
getSize: [Function],
getLocation: [Function],
isEnabled: [Function],
isSelected: [Function],
submit: [Function],
clear: [Function],
isDisplayed: [Function],
getOuterHtml: [Function],
getInnerHtml: [Function],
getId: [Function] }
答案 0 :(得分:0)
测试Angular很困难。不要沮丧自己。 :)
尝试以下两件事:
与CSS selectors更具针对性。添加#idTag
以确保您点击所需的完全元素:
element(by.id('idTag')).click();
写一个断言。你的测试没有测试任何东西。它只是单击菜单项。点击后会发生什么?例如,是否应该在屏幕上弹出一个新元素?
expect(element(by.id('newPatient')).isPresent()).toBe(true);
答案 1 :(得分:0)
要在控制台上打印值,您需要执行以下操作:
var dropdown = element.all(by.css('.dropdown')).get(3).getText();
dropdown.then(function(value)
{
console.log("Dropdown Log*****", value);
});
原因:
var下拉包含承诺。要打印该值,您需要使用 .then 提取其值
处理承诺的另一种方法是使用 expect 语句
请告诉我这是否有帮助!