package pt.fccn.mobile.arquivo.tests.pagesearch;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.openqa.selenium.By;

import pt.fccn.arquivo.selenium.Retry;
import pt.fccn.arquivo.selenium.WebDriverTestBaseParalell;

/**
 *
 * @author Ivo Branco <ivo.branco@fccn.pt>
 *
 */
public class PageSearchTest extends WebDriverTestBaseParalell {

	public PageSearchTest(String os, String version, String browser, String deviceName, String deviceOrientation) {
		super(os, version, browser, deviceName, deviceOrientation);
	}

	@Test
	@Retry
	public void pageSearchTest() {
		run("Search fccn", () -> {
			driver.findElement(By.id("txtSearch")).clear();
			driver.findElement(By.id("txtSearch")).sendKeys("fccn");
			driver.findElement(By.xpath("//*[@id=\"buttonSearch\"]/button")).click();
		});

		waitUntilElementIsVisibleAndGet(By.id("resultados-lista"));

		long emsCount = driver.findElementsByXPath("//*[@id=\"resultados-lista\"]//em") //
				.stream() //
				.filter(em -> em.getText().toLowerCase().contains("fccn")) //
				.count();

		System.out.println("emsCount " + emsCount);

		int anchorsCount = driver.findElementsByXPath("//*[@id=\"resultados-lista\"]//a[contains(text(),'fccn')]")
				.size();

		System.out.println("anchorsCount " + anchorsCount);

		assertTrue("At least 80 percent of results should show something related to search criteria",
				emsCount + anchorsCount >= 10);
	}

}

@@ -239,16 +239,17 @@
 aralell;
+ 
 %0A%0A/**%0A *
@@ -814,16 +814,19 @@
 %0A%09%09%7D);%0A%0A
+%09%09%0A
 %09%09waitUn
@@ -883,18 +883,23 @@
 ));%0A
+%09%09
 %0A%09%09
-long em
+int anchor
 sCou
@@ -966,109 +966,62 @@
 %22%5D//
-em%22) //%0A%09%09%09%09.stream() //%0A%09%09%09%09.filter(em -%3E em.getText().toLowerCase().contains(%22fccn%22)) //
+*%5B@class=%5C%22url%5C%22%5D%5Bcontains(text(),'fccn')%5D%22)
 %0A%09%09%09%09.
-count
+size
 ();%0A
@@ -1043,18 +1043,22 @@
 rintln(%22
-em
+anchor
 sCount %22
@@ -1060,18 +1060,22 @@
 unt %22 + 
-em
+anchor
 sCount);
@@ -1075,29 +1075,28 @@
 Count);%0A
+%09%09
 %0A%09%09
-int anchor
+long em
 sCount =
@@ -1159,46 +1159,109 @@
 %22%5D//
-a%5Bcontains(text(),'fccn')%5D%22)
+em%22) //%0A%09%09%09%09.stream() //%0A%09%09%09%09.filter(em -%3E em.getText().toLowerCase().contains(%22fccn%22)) //
 %0A%09%09%09%09.
-size
+count
 ();%0A
@@ -1275,38 +1275,34 @@
 em.out.println(%22
-anchor
+em
 sCount %22 + ancho
@@ -1288,38 +1288,34 @@
 n(%22emsCount %22 + 
-anchor
+em
 sCount);%0A%0A%09%09asse

Fix PageSearchTest