나는 각도기를 처음 접했고 (실제로 작동하는) 아래 코드를 작성한 방법에 만족하지 않습니다.
단순히 변수 (여기, "nb_before")에 카운트를 저장하고 다시 사용하고 싶지만 약속 메커니즘으로는 내가 간결하게 할 수 없기 때문에 모든 것을 같은 함수에 넣기로했습니다. 하지만 너무 추해.
내가 누락 된 것이 있습니까?각도기의 요소 수를 올바르게 저장하는 방법
it("Test case", function() {
browser.get(browser.baseUrl);
var button = element(by.xpath("//whatever"));
var rows = element.all(by.xpath("//whatever"));
button.click(); // adds a line
expect(rows.last().getText()).toEqual("yay");
});
우리는하지만, 이전의 수를 얻을 수 있으며, 버튼 클릭 후 : 마지막 행을 얻기 위해 여기 .last()
method을 사용했습니다 수처럼 보이는
안부
// We count the lines, we click on a button which adds a new line,
// then we verify that the new line has a specific text.
it("Test case", function() {
browser.get(browser.baseUrl);
var button = element(by.xpath("//whatever"));
var rows = element.all(by.xpath("//whatever"));
rows.count().then(function(count){
nb_before = count;
button.click(); // adds a line
var nb_after = nb_before + 1;
var new_line = element(by.xpath("//li[" + nb_after + "]"));
expect(new_line.getText()).toEqual("yay");
});
});
어디에서 다시 사용 하시겠습니까? 당신은'nb_before'을 없애고'count'를 그냥 쓸 수 있습니다. –
의사 코드에서 그 일을하고 싶습니다. var nb_before = element.all (by.xpath ("// whatever"). count(); // (자바 세계에서 왔고이 경우 실제로 더 간단합니다.)'(모든 약속 구조없이)'nb_before '를 제거하고 싶지는 않습니다. 행이 실제로 추가되었습니다. –