package pt.fccn.sobre.arquivo.pages;

import java.io.FileNotFoundException;
import java.nio.charset.Charset;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import pt.fccn.arquivo.tests.util.AnalyzeURLs;

public class SiteMapPage {

	WebDriver driver;
	private final int timeout = 50;
	
	public SiteMapPage( WebDriver driver ) throws FileNotFoundException{
		this.driver = driver;

	}
	
	public boolean checkSiteMap( String language ) {
		System.out.println( "[checkSiteMap]" );
		String idDiv = "";
		if( language.equals( "EN" ) )
			idDiv = "post-2764";
		else 
			idDiv = "post-2659";

		String xpathDiv = "//*[@id=\""+ idDiv +"\"]/div/div/div"; //find the div tag
		try{
		   WebElement divTag = ( new WebDriverWait( driver, timeout ) ) /* Wait Up to 50 seconds should throw RunTimeExcpetion*/
	                .until(
	                		ExpectedConditions.presenceOfElementLocated(
	                				By.xpath( xpathDiv ) ) );
	        
		   //find all the a tags in the div tag
		   List< WebElement > allAnchors = divTag.findElements( By.tagName( "a" ) );
    		
		   System.out.println( "[SiteMap] results size = " + allAnchors.size( ) );
		   for( WebElement elem : allAnchors ) {
			   String url = elem.getAttribute( "href" );
			   int statusCode = AnalyzeURLs.linkExists( url );
			   String text = elem.getText( );
			   Charset.forName( "UTF-8" ).encode( text );
			   if( !AnalyzeURLs.checkOk( statusCode ) ) {
				   System.out.println( "Failed: text[" + text + "] link[" + url + "] status-code[" + statusCode + "]" );
				   return false;
			   }
		   }
    		
		   return true;
    	} catch( NoSuchElementException e ){
            System.out.println( "Error in checkOPSite" );
            e.printStackTrace( );
            return false;
    	}
    	
	}
	

	
}

@@ -771,16 +771,39 @@
 %22EN%22 ) )
+%7B%0A%09%09%09switchLanguage( );
 %0A%09%09%09idDi
@@ -821,16 +821,17 @@
 764%22;%0A%09%09
+%7D
 else %0A%09%09
@@ -2041,13 +2041,460 @@
  %09%0A%09%7D%0A%09%0A
+    /**%0A    * Change to the English version%0A    */%0A    private void switchLanguage( )%7B%0A    %09String xpathEnglishVersion = %22//*%5B@id=%5C%22menu-item-4506-en%5C%22%5D/a%22;%0A      %09if( driver.findElement( By.xpath( xpathEnglishVersion ) ).getText( ).equals( %22English%22 ) ) %7B%0A      %09%09System.out.println( %22Change language to English%22 );%0A      %09%09driver.findElement( By.xpath( xpathEnglishVersion ) ).click( );%0A      %09%09IndexSobrePage.sleepThread( );%0A      %09%7D%0A    %7D%0A    
 %0A%09%0A%7D%0A

Add switch language