I am a beginner when it comes to using Protractor and I am not entirely satisfied with the code snippet below, even though it is functional.
My goal is to store the count in a variable (named "nb_before") and use it later on. However, due to the promise mechanism in place, I find it difficult to achieve concisely. This led me to cram everything into a single function, resulting in quite an ugly piece of code.
Could it be that I am overlooking something crucial?
Warm regards
// The purpose here is to count the lines, click a button to add a new line,
// and then confirm that the new line contains 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");
});
});