css에서 요소를 사용하여 요소가 투영기에 있는지 확인합니다.
각도기 엔드 투 엔드 테스트에서 내 코드인 요소(by.css(...))를 사용하여 요소가 존재하는지 확인하고 싶다.
var myElement = element(by.css('.elementClass'));
expect(myElement).toBeUndefined;
이 테스트에서는 다음과 같이 표시됩니다.
Expected { locator_ : { using : 'css selector', value : 'div[ng-switch-
when="resultNav"]' }, parentElementFinder_ : null, opt_actionResult_ :
undefined, opt_index_ : undefined, 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, toWireValue :
Function } to be undefined.
그 후 나는 약속을 사용하려고 했다.
element(by.css('.elementClass')).then( functtion(data) {
expect(data.getText()).toBeUndefined();
});
그 결과, 다음의 에러가 발생합니다.
오류: 로케이터 기준을 사용하여 요소를 찾을 수 없습니다.Css Selector(...)
네, 요소를 찾을 수 없다는 것은 알고 있습니다만, 요소를 사용하여 동작 테스트를 작성하려면 어떻게 해야 합니까?by.css(...)
)?
이거 어떻게 하는지 아는 사람 있어요?또는element(by.css())
여기서 사용하는 방법이 없습니까?
테스트 할 수 있습니다.element
이 있다isPresent
. 여기 이 절단기 문서가 있습니다.isPresent
기능.
그래서 당신의 코드는 다음과 같습니다.
var myElement = element(by.css('.elementClass'));
expect(myElement.isPresent()).toBeFalsy();
요소가 존재하지 않는지 테스트해야 합니다.
expect(element(by.css('.elementClass')).isPresent()).toBe(false);
Truthy 및 false는 함수가 다른 유형의 값을 반환하지 않는 한 부울로 강제된 후 true 및 false로 평가된 값을 나타냅니다.
var myElement = element(by.css('.elementClass'));
myElement.isPresent().then(function (elm)
{
if (elm)
{
console.log("... Element was found")
expect(myElement.getText()).toBeUndefined();
} else {
console.log("... Element was not found")
}
});
동일하지만 구문이 다르다.
let elem = $('.elementClass');
let elemIsPresent = await elem.isPresent();
expect(elemIsPresent).toBe(false);
언급URL : https://stackoverflow.com/questions/28024342/use-element-by-css-to-check-if-element-exists-in-protractor
'programing' 카테고리의 다른 글
제품 코드 구축 방법 및 사용 방법 웹 팩 (0) | 2023.02.12 |
---|---|
Woocommerce에서 체크아웃 필드를 생성하는 제품 수량에 따른 ACF 리피터 (0) | 2023.02.11 |
워드프레스에서 세션 변수를 사용하는 방법은 무엇입니까? (0) | 2023.02.11 |
"Uncatched SyntaxError"의 원인:$.parseJSON() 및 JSON.parse()가 포함된 예기치 않은 토큰 o" (0) | 2023.02.11 |
React에서 확인란 속성 설정 (0) | 2023.02.11 |