Reputation: 1334
I want to test if two elements in two different pages are equal. The reason for this is that I need to check a "copy" function that already works in my page, so both elements (divs in this case) have to be indentical:
I found that there's a method in protractor for element objects called "clone" but doesn't explains its purpose that much. Anyway I tried this:
// In the first page:
browser.get("/page1");
var clone1 = element(by.id("firstElem")).clone();
// then navigating to the other page
browser.get("/page2");
var clone2 = element(by.id("secondElem")).clone();
// then the expectation of them to be equal
expect(clone1).toEqual(clone2);
but the expectation fails with a very heavy stacktrace. Also tried comparing:
expect(clone1 == clone2).toBeTruthy();
which fails again.
What is "clone()" supposed to be used for? and,
How do I compare two divs in two separate pages for being identical?
Upvotes: 3
Views: 1122
Reputation: 473873
What is "clone()" supposed to be used for?
I've recently created a closely related question, you can follow the updates there:
How do I compare two divs in two separate pages for being identical?
Depending on your end goal, you may compare "outer HTML" representations of the elements using getOuterHtml()
, example:
browser.get("/page1");
element(by.id("firstElem")).getOuterHtml().then(function(value) {
browser.get("/page2");
expect(element(by.id("secondElem")).getOuterHtml()).toEqual(value);
});
Upvotes: 2
Reputation: 5264
try without clone
browser.get("/page1");
var clone1 = element(by.id("firstElem"));
browser.get("/page2");
var clone2 = element(by.id("secondElem"));
expect(clone1).toEqual(clone2);
Upvotes: 0
Reputation: 4020
Can you try this:
expect(angular.equals(clone1, clone2).toBe(true));
Read more about angular.equals here: https://docs.angularjs.org/api/ng/function/angular.equals
Upvotes: 0