tags:

views:

77

answers:

3

Hi ,

I have to check the differences between 2 html documents One is an old doc another is the updated document I need selenium to get the source of the 2 documents and then do a comparison to check the diff How can i acheive this in java & selenium

Below is the flow i have , can anyone give ideas/examples in how to implement this

Many thanks

  • Go to the old page using Selenium
  • Collect all the data for the old web page
  • Convert the data to a standard format (XML probably); create a class to do this
  • Save the data to a file
  • Go to the new page using Selenium
  • Collect all the data for the new web page
  • Convert the data to a standard format (XML probably); use the class you created to do this
  • Save the data to a file
  • Use a Java library to diff the two files
A: 

u could use javascript method document.innerHTML or document.innerText

01
Could you explain a bit in detail please
Getafix
A: 

Use selenium.getHtmlSource() for each page and either compare the returned Strings in Java or save them to files and use a command line tool such as "diff".

If using Java, two methods I can think of are using something like StringUtils.difference() (almost certainly a mess) or better yet Google Diff. Google diff has a Java library and test example.

Of course the outputs of these will be a literal diff, you might want something more custom to make sense of changes in HTML.

dhackner
A: 

Hi Dhackner,

Thanks for your reply!

Yes i am using Java with selenium RC

I used the StringUtils.difference() method to get the difference between 2 URLs and saved it as a text file

Yes as you mentioned its only a literal diff

Maybe i have to play with Google Diff

Thanks for that information and help

---------------------code----------------------------------- selenium.open("http://aa.bb.cc/x"); String FirstPage = selenium.getHtmlSource(); selenium.open("http://aa.bb.cc/y"); String SecondPage = selenium.getHtmlSource();
String Diff = StringUtils.difference(FirstPage,SecondPage); System.out.println("The difference between first and second url is " +Diff);
File f = new File("C:/folder/" + "MSDSDiff" + ".txt"); FileWriter writer = new FileWriter(f); writer.append(Diff); writer.close(); System.out.println("Diff report is in Location : " + f.getAbsolutePath());

Getafix