Reputation: 670
I am trying to make my code more readable in portractor. I want to store the css class in a variable and need to access that variable on 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);
});
So I created 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')\"]\"";
And tried to access my css class using that variable:
element.all(by.css(road_button)).click();
element.all(by.css(road_missing)).click();
But some how I'm not able to access these variable value. Can you please provide me the right way of doing this? Thank you
Upvotes: 1
Views: 72
Reputation: 473873
I think you are sort of reinventing the wheel. What you really need to follow is the guideline to use Page Objects. They would not only solve your problem of separating locators from the test flow and test scenario logic, but would also make the the code more modular and easy to adapt to never-ending changes on the application side.
Here is a great practical introduction to Page Objects in Protractor:
Upvotes: 1