<commit_before>/**
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 * Copyright (C) 2011 SAW Group - FCCN <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package pt.fccn.arquivo.pages;



import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


import javax.xml.parsers.ParserConfigurationException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.io.StringReader;
import java.sql.Driver;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import net.sourceforge.htmlunit.corejs.javascript.ast.NewExpression;


/**
 * @author <NAME>
 *
 */
public class OpenSearchPage {
    private final WebDriver driver;
    private final String numberOfResultsTag = "feedContent";
    private final String listOfResultsTag = "resultados-lista";
    private static final String searchBox = "txtSearch";
    private static final String searchButton = "btnSubmit";
    private final String pageURLCheck = "opensearch";

 // Patern to detect if there are results
    private Pattern noResultsPattern = Pattern.compile("\\d Resultados");
    private boolean isPredProd=false;

    private Document doc;
    /**
     * Create a new OpenSearchPage from navigation Document contains the XML From Opensearch
     * @param driver
     */
    public OpenSearchPage(WebDriver driver,boolean isPreProd, Document doc){  
        this.isPredProd=isPreProd;
        this.driver= driver;
        this.doc = doc;
        System.out.println("New OpenSearchPage, CurrentURL: " + driver.getCurrentUrl());
    }
    /**
     * Create a new OpenSearchPage from navigation
     * @param driver
     */
    public OpenSearchPage(WebDriver driver,boolean isPreProd){	
    	this.isPredProd=isPreProd;
        this.driver= driver;
        // Check that we're on the right page.
        if (!(driver.getCurrentUrl().contains(pageURLCheck))) {
            throw new IllegalStateException("This is not the results opensearch page\n URL of current page: " + driver.getCurrentUrl());
        }
    }
    
    /**
     * Gather search for a term
     * @param query Term that was searched
     * @return true if the term exists in the first result title or in the snippet text
     */
    public boolean existsResults() throws Exception{
        System.out.println("Checking if results are presented!");
        String resultsTags = driver.findElement(By.id(numberOfResultsTag)).getText();
        WebElement listOfTitles = driver.findElement(By.xpath("//*[@id='feedContent']"));
        
        if (resultsTags.length()<=0)
        	return false;
//                throw new Exception("No results for term");
        return true;
    }
    /**
     * Verify coherence in result between opensarch api and search on arquivo.pt
     * @param firstTitleOfResultList The first result when searching for a query through arquivo.pt full text-search
     * @return true if the first result are coherent with opensearch result, false otherwises
     */
    public boolean inspectCoherence(String firstTitleOfResultList) {
        WebElement listOfTitles = driver.findElement(By.xpath("//*[@id='feedContent']"));
        String resultTitle = listOfTitles.getText().split("\n")[0];
        return resultTitle.contains(firstTitleOfResultList);	
    }

    /**
     * It is only needed when the test is run individually, if not IndexPage will set this variable
     * Verify that the term exists in as a search result
     * @param query Term that was searched
     * @return true if the term exists in the first result title or in the snippet text
     */
    public String setFirstResult(String searchTerms) {
    	
        System.out.println("The URL: " + driver.getCurrentUrl());
        String openSearchUrl = driver.getCurrentUrl();

        //driver.get(openSearchUrl.split("opensearch")[0]);
    	driver.findElement(By.id(searchBox)).clear();
    	driver.findElement(By.id(searchBox)).sendKeys(searchTerms);
    	driver.findElement(By.id(searchButton)).submit();
    	WebElement listOfResults = driver.findElement(By.id(listOfResultsTag));
    	String result = listOfResults.findElement(By.xpath("//*[@id=\"resultados-lista\"]/ul/li[1]/h2")).getText(); 
        //driver.get(openSearchUrl);
        return result;
    }
    
    
}
<commit_msg>Fixing TestSearchOneTermOpenSearch for mobile<commit_after>/**
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 * Copyright (C) 2011 SAW Group - FCCN <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package pt.fccn.arquivo.pages;



import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


import javax.xml.parsers.ParserConfigurationException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.io.StringReader;
import java.sql.Driver;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import net.sourceforge.htmlunit.corejs.javascript.ast.NewExpression;


/**
 * @author <NAME>
 *
 */
public class OpenSearchPage {
    private final WebDriver driver;
    private final String numberOfResultsTag = "feedContent";
    private final String listOfResultsTag = "resultados-lista";
    private static final String searchBox = "txtSearch";
    private static final String searchButton = "btnSubmit";
    private final String pageURLCheck = "opensearch";

 // Patern to detect if there are results
    private Pattern noResultsPattern = Pattern.compile("\\d Resultados");
    private boolean isPredProd=false;

    private Document doc;
    /**
     * Create a new OpenSearchPage from navigation Document contains the XML From Opensearch
     * @param driver
     */
    public OpenSearchPage(WebDriver driver,boolean isPreProd, Document doc){  
        this.isPredProd=isPreProd;
        this.driver= driver;
        this.doc = doc;
        System.out.println("New OpenSearchPage, CurrentURL: " + driver.getCurrentUrl());
    }
    /**
     * Create a new OpenSearchPage from navigation
     * @param driver
     */
    public OpenSearchPage(WebDriver driver,boolean isPreProd){	
    	this.isPredProd=isPreProd;
        this.driver= driver;
        // Check that we're on the right page.
        if (!(driver.getCurrentUrl().contains(pageURLCheck))) {
            throw new IllegalStateException("This is not the results opensearch page\n URL of current page: " + driver.getCurrentUrl());
        }
    }
    
    /**
     * Gather search for a term
     * @param query Term that was searched
     * @return true if the term exists in the first result title or in the snippet text
     */
    public boolean existsResults() throws Exception{
        System.out.println("Checking if results are presented!");
        String resultsTags = driver.findElement(By.id(numberOfResultsTag)).getText();
        WebElement listOfTitles = driver.findElement(By.xpath("//*[@id='feedContent']"));
        
        if (resultsTags.length()<=0)
        	return false;
//                throw new Exception("No results for term");
        return true;
    }
    /**
     * Verify coherence in result between opensarch api and search on arquivo.pt
     * @param firstTitleOfResultList The first result when searching for a query through arquivo.pt full text-search
     * @return true if the first result are coherent with opensearch result, false otherwises
     */
    public boolean inspectCoherence(String firstTitleOfResultList) {
        WebElement listOfTitles = driver.findElement(By.xpath("//*[@id='feedContent']"));
        String resultTitle = listOfTitles.getText().split("\n")[0];
        return resultTitle.contains(firstTitleOfResultList);	
    }

    /**
     * It is only needed when the test is run individually, if not IndexPage will set this variable
     * Verify that the term exists in as a search result
     * @param query Term that was searched
     * @return true if the term exists in the first result title or in the snippet text
     */
    public String setFirstResult(String searchTerms) {
    	
        System.out.println("The URL: " + driver.getCurrentUrl());
        String openSearchUrl = driver.getCurrentUrl();

        //driver.get(openSearchUrl.split("opensearch")[0]);
    	driver.findElement(By.id(searchBox)).clear();
    	driver.findElement(By.id(searchBox)).sendKeys(searchTerms);
    	driver.findElement(By.id(searchButton)).submit();
    	WebElement listOfResults = driver.findElement(By.id(listOfResultsTag));
    	String result = listOfResults.findElement(By.xpath("//*[@id=\"resultados-lista\"]/ul/li[1]/h2")).getText(); 
        //driver.get(openSearchUrl);

        System.out.println("Result: " + result);
        return result;
    }
    
    
}

{'fraction_non_alphanumeric': 0.10079350085017948, 'fraction_numerical': 0.0043453617986019275, 'mean_word_length': 3.362175525339926, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4731671', 'n_tokens_mistral': 3015, 'n_tokens_neox': 2961, 'n_words': 919}