I am working on improving the readability of my code in Protractor. My goal is to assign a CSS class to a variable and then use that variable within a click method.
element.all(by.css("div[ng-click=\"setLocation('report_road')\"]")).click();
element.all(by.css("div[ ng-click=\"mapFeedBack.editObject= mapFeedBack.createMapObjectModel();setLocation(mapFeedBack.noMap?'road_new':'choose_location_road_new/road_new')\"]")).click();
it("test browser should reach report road option",function() //spec2s
{
element.all(by.css("div[ng-click=\"setLocation('report_road')\"]")).click();
expect(browser.getCurrentUrl()).toContain("report_road");
browser.sleep(browser.params.sleeptime);
browser.sleep(browser.params.sleeptime);
});
it("test browser should reach report road missing",function() //spec3
{
element.all(by.css("div[ ng-click=\"mapFeedBack.editObject= mapFeedBack.createMapObjectModel();setLocation(mapFeedBack.noMap?'road_new':'choose_location_road_new/road_new')\"]")).click();
expect(browser.getCurrentUrl()).toContain("choose_location_road_new/road_new");
browser.sleep(browser.params.sleeptime);
browser.sleep(browser.params.sleeptime);
});
As part of my approach, I have defined two variables in my file:
var road_button ="\"div[ng-click=\"setLocation('report_road')\"]\"";
var road_missing= "\"div[ ng-click=\"mapFeedBack.editObject= mapFeedBack.createMapObjectModel();setLocation(mapFeedBack.noMap?'road_new':'choose_location_road_new/road_new')\"]\"";
I attempted to access the CSS class using these variables:
element.all(by.css(road_button)).click();
element.all(by.css(road_missing)).click();
However, I encountered an issue with accessing the values stored in these variables. Could you please guide me on the correct way to achieve this? Thank you.