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?
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With