对于脚本语言来说,在类型记录中使用枚举和if else语句有问题。作为一种替代,我使用的是开关情况,而不是其他条件。
我试过了!==,!===,这似乎不管用。如果条件不等于比较值,则枚举的第一个索引不起作用,除非我做了它。
public static async getElementByLocatorType(locatorType: customLocators, locatorValue: string, expectedText?: string) {
if (locatorType! === customLocators.CSS) {
return element(by.css(locatorValue));
} else if (locatorType === customLocators.XPATH) {
return element(await by.xpath(locatorValue));
} else if (locatorType === customLocators.CSSTEXT) {
return element(by.cssContainingText(locatorValue, expectedText));
} else if (locatorType === customLocators.LINKTEXT) {
return element(by.linkText(locatorValue));
} else if (locatorType === customLocators.BUTTONTEXT ) {
return element(by.buttonText(locatorValue));
} else if (locatorType === customLocators.PARTIALBUTTONTEXT) {
return element(by.partialButtonText(locatorValue));
} else if (locatorType === customLocators.PARTIALLINKTEXT ) {
return element(by.partialLinkText(locatorValue));
} else {
logger.info('Cannot find any locator listed above');
}
}
export enum customLocators {
'CSS', 'XPATH', 'CSSTEXT', 'LINKTEXT', 'BUTTONTEXT', 'PARTIALBUTTONTEXT', 'PARTIALLINKTEXT'
}没有找到的元素(by.css)其他元素工作得很好,除了(枚举的第一个索引) locatorType === customLocators.CSS
发布于 2019-10-18 14:16:33
如前所述,我使用了开关箱作为一种可以正常工作的替代方案。
public static async getElementByLocatorType(locatorType: customLocators,
locatorValue: string, expectedText?: string) {
switch (locatorType) {
case customLocators.CSS:
return element(by.css(locatorValue));
break;
case customLocators.XPATH:
return element(by.xpath(locatorValue));
break;
case customLocators.LINKTEXT:
return element(by.linkText(locatorValue));
break;
case customLocators.BUTTONTEXT:
return element(by.buttonText(locatorValue));
break;
case customLocators.CSSTEXT:
return element(by.cssContainingText(locatorValue, expectedText));
break;
case customLocators.PARTIALLINKTEXT:
return element(by.partialLinkText(locatorValue));
break;
case customLocators.PARTIALBUTTONTEXT:
return element(by.partialButtonText(locatorValue));
break;
default:
logger.info('browser : ' + locatorType + ' is invalid, Please check the selector name..');
}
}https://stackoverflow.com/questions/58439961
复制相似问题