Reputation: 678
I have a URL which I want to test the changes in it if I browse to this URL several time , meaning: If this is the first time that a test is running on this url, only save the layout (DOM) of the page. and I want to be able to produce output which will contain the following: list of all changes on this url, changes mean - new HTML elements added to the page, old elements was removed, elements location have changed.
So far what I started to do with selenium is:
public String extractingUrlDom(){
this.driver.get("https://www.google.com/");
this.str = driver.getPageSource().toString();
return str;
}
My question is how do I track all changes that was done to the DOM after browsing to the same URL (if any changes were done).
Upvotes: 1
Views: 772
Reputation: 25621
You would need to write the HTML to a text file in a specific location. When a test runs, it would check that location for the expected filename. If it doesn't exist, it's the first time the test was run and it would save the HTML to the file. If a file does exist, you would open the existing file and do a diff of the two HTML strings. You could then write that diff out to a separate file.
There's more logic that you would want to consider but this should be enough to get you started. There are plenty of diffing engines/libraries out there, you should be able to find an existing one and use it.
Upvotes: 2