2017-04-30 10 views
0

ウェブページの変更をすべて一覧表示する方法はありますか?変更すると、ページに追加された新しいhtml要素、削除された古い要素、いくつかの要素の位置が変更されたことを意味します。ウェブページのすべての変更をリストする方法はありますか?

私はjavaでselenium web driverを使用しています。これは私のコードです:

  @Test(dataProvider = "deviceName") 
     public void mobileEmulation(String deviceName, String url){ 

      String ChromeDriverPath = "C:\\chromedriver_win32\\chromedriver.exe"; 
      System.setProperty("webdriver.chrome.driver", ChromeDriverPath); 
      Map<String, String> mobileEmulation = new HashMap<String, String>(); 
      mobileEmulation.put("deviceName", deviceName); 

      Map<String, Object> chromeOptions = new HashMap<String, Object>(); 
      chromeOptions.put("mobileEmulation", mobileEmulation); 
      DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
      capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); 
      WebDriver driver = new ChromeDriver(capabilities); 

      for (int i = 0 ; i < 2 ; i ++){ 
       driver.get(url); 
       String source=driver.getPageSource(); 
      } 

      driver.quit(); 
     } 

私はそれを行うにはどのようには考えているかを開始する場所から以来、私はこだわっていますか?

+0

XHTMLの場合は、XMLUnit:http://javarevisited.blogspot.co.uk/2017/04/how-to-compare-two-xml-files-in-java.htmlを試してください。それがXHTMLでない場合、それを修正する方法があります:http://stackoverflow.com/questions/29087077/is-it-possible-to-convert-html-into-xhtml-with-jsoup-1-8-1 – slim

答えて

0

デフォルトのページの変更とモバイル版のページの変更を比較して、その違いを確認しているようですね。その場合、モバイル用にエミュレートされていないページソースの文字列をパラメータとして渡してから、モバイルのページソースとデフォルトページを比較します。このようなものをExtract the difference between two strings in Javaのように使用すると、2つのソースの違いを表示できます。これを行うには

良い方法は、この

public String getDefaultSource(String deviceName, String url){  
     String ChromeDriverPath = "C:\\chromedriver_win32\\chromedriver.exe"; 
     System.setProperty("webdriver.chrome.driver", ChromeDriverPath); 
     WebDriver driver = new ChromeDriver(); 
     driver.get(url); 
     return driver.getPageSource(); 
    } 
    public String getMobileSource(String deviceName, String url){ 
     String ChromeDriverPath = "C:\\chromedriver_win32\\chromedriver.exe"; 
     System.setProperty("webdriver.chrome.driver", ChromeDriverPath); 
     Map<String, String> mobileEmulation = new HashMap<String, String>(); 
     mobileEmulation.put("deviceName", deviceName); 

     Map<String, Object> chromeOptions = new HashMap<String, Object>(); 
     chromeOptions.put("mobileEmulation", mobileEmulation); 
     DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
     capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); 
     WebDriver driver = new ChromeDriver(capabilities); 
     driver.get(url); 
     return driver.getPageSource(); 
    } 
    public void compareSource(String defSource, String mobileSource){ 
      //You can used google's diff_match_patch library to get string differences 
     } 

次に、あなただけのソースのそれぞれを取得し、文字列を比較しますと、それは2間のすべての相違を示さなければならないようなものかもしれません。

関連する問題