Commit 2e97f5afb5093e38537356d4f992234fea86287c

Authored by Nelson Torres Universidade U Minho
1 parent 338ecdd359
Exists in master

Lareferencia's tests using DataProvider

TestNGResources/Lrharvester/testng-lrharvester.xml
... ... @@ -11,14 +11,14 @@
11 11 <class name="testng.lrharvester.TestAddValidatorLrharvester"/>
12 12 <class name="testng.lrharvester.TestAddNetworkLrharvester"/>
13 13 <class name="testng.lrharvester.TestAddOaiLrharvester"/>
14   - -->
  14 +
15 15 <class name="testng.lrharvester.TestHarvestFullLrharvester"/>
16 16 <class name="testng.lrharvester.TestTransformValidateFullLrharvester"/>
17   - <!--
  17 +
18 18 <class name="testng.lrharvester.TestAddDescargadeODLrharvester"/>
19   - -->
  19 +
20 20 <class name="testng.lrharvester.TestIndexVufindLrharvester"/>
21   - <!--
  21 +
22 22 <class name="testng.lrharvester.TestIndexHistoricLrharvester"/>
23 23 -->
24 24 </classes>
... ...
TestNGResources/Lrharvester/testng-portal-beanshell.xml
... ... @@ -1,85 +0,0 @@
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!-- Threading count to execute paralel tests and parallel set to tests (classes see documentation) -->
3   -<!-- I think if We have 2 classes they will run in parallel -->
4   -<suite name="LrHarvester" >
5   -
6   - <test name="LrharvesterChrome">
7   - <!-- These are defined in the maven and in the Test Files -->
8   - <!-- groups are overlaped -->
9   - <method-selectors>
10   - <method-selector>
11   - <script language="beanshell"><![CDATA[
12   - String grps = System.getProperty("browserToRun");
13   - return grps.contains("chrome") || grps.contains("all");
14   - ]]></script>
15   - </method-selector>
16   -</method-selectors>
17   - <parameter name="browser" value="chrome" />
18   - <classes>
19   - <class name="testng.lrharvester.TestLoginLrharvester"/>
20   - <class name="testng.lrharvester.TestAddValidatorLrharvester"/>
21   - <class name="testng.lrharvester.TestAddNetworkLrharvester"/>
22   - <class name="testng.lrharvester.TestAddOaiLrharvester"/>
23   - <class name="testng.lrharvester.TestAddHarvestFullLrharvester"/>
24   - <class name="testng.lrharvester.TestAddTransformValidateFullLrharvester"/>
25   - <class name="testng.lrharvester.TestAddDescargadeODLrharvester"/>
26   - <class name="testng.lrharvester.TestIndexVufindLrharvester"/>
27   - <class name="testng.lrharvester.TestIndexHistoricLrharvester"/>
28   - </classes>
29   - </test>
30   -
31   - <test name="LrharvesterFirefox">
32   - <!-- These are defined in the maven and in the Test Files -->
33   - <!-- groups are overlaped -->
34   - <method-selectors>
35   - <method-selector>
36   - <script language="beanshell"><![CDATA[
37   - String grps = System.getProperty("browserToRun");
38   - return grps.contains("firefox") || grps.contains("all");
39   - ]]></script>
40   - </method-selector>
41   -</method-selectors>
42   - <parameter name="browser" value="firefox" />
43   - <classes>
44   - <class name="testng.lrharvester.TestLoginLrharvester"/>
45   - <class name="testng.lrharvester.TestAddValidatorLrharvester"/>
46   - <class name="testng.lrharvester.TestAddNetworkLrharvester"/>
47   - <class name="testng.lrharvester.TestAddOaiLrharvester"/>
48   - <class name="testng.lrharvester.TestAddHarvestFullLrharvester"/>
49   - <class name="testng.lrharvester.TestAddTransformValidateFullLrharvester"/>
50   - <class name="testng.lrharvester.TestAddDescargadeODLrharvester"/>
51   - <class name="testng.lrharvester.TestIndexVufindLrharvester"/>
52   - <class name="testng.lrharvester.TestIndexHistoricLrharvester"/>
53   - </classes>
54   - </test>
55   -
56   - <test name="LrhatvesterHeadless">
57   - <!-- These are defined in the maven and in the Test Files -->
58   - <!-- groups are overlaped -->
59   - <method-selectors>
60   - <method-selector>
61   - <script language="beanshell"><![CDATA[
62   - String grps = System.getProperty("browserToRun");
63   - return grps.contains("headless") || grps.contains("all");
64   - ]]></script>
65   - </method-selector>
66   -</method-selectors>
67   - <parameter name="browser" value="headless" />
68   - <classes>
69   - <class name="testng.lrharvester.TestLoginLrharvester"/>
70   - <class name="testng.lrharvester.TestAddValidatorLrharvester"/>
71   - <class name="testng.lrharvester.TestAddNetworkLrharvester"/>
72   - <class name="testng.lrharvester.TestAddOaiLrharvester"/>
73   - <class name="testng.lrharvester.TestAddHarvestFullLrharvester"/>
74   - <class name="testng.lrharvester.TestAddTransformValidateFullLrharvester"/>
75   - <class name="testng.lrharvester.TestAddDescargadeODLrharvester"/>
76   - <class name="testng.lrharvester.TestIndexVufindLrharvester"/>
77   - <class name="testng.lrharvester.TestIndexHistoricLrharvester"/>
78   - </classes>
79   - </test>
80   -
81   - <listeners>
82   - <listener class-name="org.uncommons.reportng.HTMLReporter"/>
83   - <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
84   - </listeners>
85   -</suite>
86 0 \ No newline at end of file
src/test/java/dataproviders/DataProviderLaReferencia.java
... ... @@ -0,0 +1,27 @@
  1 +package dataproviders;
  2 +
  3 +import org.testng.annotations.DataProvider;
  4 +
  5 +import java.util.Arrays;
  6 +import java.util.Iterator;
  7 +
  8 +/*
  9 + * Inject this values with Spring??????
  10 + */
  11 +
  12 +public class DataProviderLaReferencia {
  13 +
  14 + //Should be in the super class
  15 + //Added this to use multiple urls -> Called in test functions with @Test and the dataprovider
  16 + //We can have multiple data providers
  17 + @DataProvider(name = "development")
  18 + public static Iterator<Object[]> urls() {
  19 + String[] urls = {
  20 + "http://dev6.rcaap.pt/backend"
  21 + };
  22 + return Arrays.stream(urls)
  23 + .map(s -> new Object[]{s})
  24 + .iterator();
  25 + }
  26 +
  27 +}
... ...
src/test/java/testng/lrharvester/TestAddDescargadeODLrharvester.java
... ... @@ -3,6 +3,7 @@ package testng.lrharvester;
3 3 import com.google.gson.JsonElement;
4 4 import com.google.gson.JsonObject;
5 5 import com.google.gson.JsonParser;
  6 +import dataproviders.DataProviderLaReferencia;
6 7 import org.openqa.selenium.By;
7 8 import org.openqa.selenium.support.ui.FluentWait;
8 9 import org.openqa.selenium.support.ui.Wait;
... ... @@ -19,13 +20,13 @@ import java.util.concurrent.TimeUnit;
19 20 import static org.testng.Assert.assertTrue;
20 21  
21 22 public class TestAddDescargadeODLrharvester extends TestBase {
22   - String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
  23 + String sURL = baseUrl + "/public/getRunningStatus";
23 24  
24 25  
25 26  
26   - @Test
27   - public void testAddValidator() throws Exception {
28   - driver.get("http://dev6.rcaap.pt/backend/home#");
  27 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  28 + public void testAddValidator(String baseUrl) throws Exception {
  29 + driver.get(baseUrl);
29 30 driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
30 31 acceptNextAlert = true;
31 32 driver.findElement(By.xpath("(//a[contains(text(),'Descarga de OD (full)')])[2]")).click();
... ...
src/test/java/testng/lrharvester/TestAddNetworkLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import dataproviders.DataProviderLaReferencia;
3 4 import org.openqa.selenium.By;
4   -import org.openqa.selenium.WebDriver;
5   -import org.openqa.selenium.firefox.FirefoxDriver;
6 5 import org.openqa.selenium.support.ui.Select;
7   -import org.testng.annotations.BeforeClass;
8 6 import org.testng.annotations.Test;
9 7 import testng.rcaap.TestBase;
10 8  
11   -import java.util.concurrent.TimeUnit;
12   -
13 9 import static org.testng.Assert.assertEquals;
14 10  
15 11 public class TestAddNetworkLrharvester extends TestBase {
16 12  
17 13  
18   - @Test
19   - public void testAddNewNetwork() throws Exception {
20   - driver.get("http://dev6.rcaap.pt/backend/home#");
  14 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  15 + public void testAddNewNetwork(String baseUrl) throws Exception {
  16 + driver.get(baseUrl);
21 17 driver.findElement(By.linkText("Nuevo repositorio")).click();
22 18 driver.findElement(By.id("acronym")).click();
23 19 driver.findElement(By.id("acronym")).clear();
... ...
src/test/java/testng/lrharvester/TestAddOaiLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import dataproviders.DataProviderLaReferencia;
  4 +import org.openqa.selenium.By;
  5 +import org.openqa.selenium.support.ui.Select;
3 6 import org.testng.annotations.Test;
4 7 import testng.rcaap.TestBase;
5 8  
6   -import static org.testng.Assert.assertTrue;
7   -
8 9 public class TestAddOaiLrharvester extends TestBase {
9 10  
10 11  
11   - @Test
12   - public void testAddOai() throws Exception {
13   - driver.get("http://dev6.rcaap.pt/backend/home#");
14   - assertTrue(false);
  12 +
  13 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  14 + public void testAddOai(String baseUrl) throws Exception {
  15 + driver.get(baseUrl);
  16 + driver.findElement(By.xpath("//button[2]")).click();
  17 + driver.findElement(By.linkText("Nuevo origen")).click();
  18 + driver.findElement(By.id("uri")).click();
  19 + driver.findElement(By.id("uri")).click();
  20 + driver.findElement(By.id("uri")).clear();
  21 + driver.findElement(By.id("uri")).sendKeys("http://arca.igc.gulbenkian.pt/oaiextended/request");
  22 + driver.findElement(By.name("metadataPrefix")).click();
  23 + new Select(driver.findElement(By.name("metadataPrefix"))).selectByVisibleText("xoai");
  24 + driver.findElement(By.xpath("//option[@value='string:xoai']")).click();
  25 + driver.findElement(By.xpath("//input[@value='Guardar']")).click();
  26 + driver.findElement(By.xpath("//div[2]/div/button")).click();
15 27 }
16 28  
17 29  
... ...
src/test/java/testng/lrharvester/TestAddValidatorLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import dataproviders.DataProviderLaReferencia;
3 4 import org.openqa.selenium.By;
4 5 import org.testng.annotations.Test;
5 6 import testng.rcaap.TestBase;
... ... @@ -7,10 +8,10 @@ import testng.rcaap.TestBase;
7 8 public class TestAddValidatorLrharvester extends TestBase {
8 9  
9 10  
10   - @Test
11   - public void testAddValidator() throws Exception {
  11 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  12 + public void testAddValidator(String baseUrl) throws Exception {
12 13  
13   - driver.get("http://dev6.rcaap.pt/backend/home#");
  14 + driver.get(baseUrl);
14 15 driver.findElement(By.linkText("Editar Validadores")).click();
15 16 driver.findElement(By.xpath("//a/span")).click();
16 17 driver.findElement(By.id("name")).click();
... ...
src/test/java/testng/lrharvester/TestHarvestFullLrharvester.java
... ... @@ -4,6 +4,7 @@ import com.google.gson.JsonArray;
4 4 import com.google.gson.JsonElement;
5 5 import com.google.gson.JsonObject;
6 6 import com.google.gson.JsonParser;
  7 +import dataproviders.DataProviderLaReferencia;
7 8 import org.openqa.selenium.By;
8 9 import org.openqa.selenium.support.ui.FluentWait;
9 10 import org.openqa.selenium.support.ui.Wait;
... ... @@ -20,14 +21,14 @@ import java.util.concurrent.TimeUnit;
20 21 import static org.testng.Assert.assertTrue;
21 22  
22 23 public class TestHarvestFullLrharvester extends TestBase {
23   - String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
  24 + String sURL = baseUrl + "/public/getRunningStatus";
24 25 URL url;
25 26 URLConnection request;
26 27  
27 28  
28   - @Test
29   - public void testHarvestFull() throws Exception {
30   - driver.get("http://dev6.rcaap.pt/backend/home#");
  29 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  30 + public void testHarvestFull(String baseUrl) throws Exception {
  31 + driver.get(baseUrl);
31 32 driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
32 33 acceptNextAlert = true;
33 34 driver.findElement(By.xpath("(//a[contains(text(),'Cosecha (full)')])[2]")).click();
... ... @@ -60,11 +61,9 @@ public class TestHarvestFullLrharvester extends TestBase {
60 61 url = new URL(sURL);
61 62 request = url.openConnection();
62 63 request.connect();
63   -
64   - // Convert to a JSON object to print data
65   - JsonParser jp = new JsonParser(); //from gson
66   - JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
67   - JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  64 + JsonParser jp = new JsonParser();
  65 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
  66 + JsonObject rootobj = root.getAsJsonObject();
68 67 JsonObject running = rootobj.getAsJsonObject("running");
69 68  
70 69 return running.size() > 0;
... ... @@ -72,16 +71,13 @@ public class TestHarvestFullLrharvester extends TestBase {
72 71  
73 72 private boolean isHarvested() throws IOException {
74 73  
75   -
76   - url = new URL("http://dev6.rcaap.pt/backend/public/listSnapshotsByNetworkAcronym/teste");
  74 + url = new URL(baseUrl + "/public/listSnapshotsByNetworkAcronym/teste");
77 75 request = url.openConnection();
78 76 request.connect();
79 77  
80   - // Convert to a JSON object to print data
81   - JsonParser jp = new JsonParser(); //from gson
82   - JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
83   - JsonArray rootobj = root.getAsJsonArray(); //May be an array, may be an object.
84   -
  78 + JsonParser jp = new JsonParser();
  79 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
  80 + JsonArray rootobj = root.getAsJsonArray();
85 81 JsonObject snapshotInfo = rootobj.get(rootobj.size() - 1).getAsJsonObject();
86 82  
87 83 int size = snapshotInfo.get("size").getAsInt();
... ...
src/test/java/testng/lrharvester/TestIndexHistoricLrharvester.java
... ... @@ -3,6 +3,7 @@ package testng.lrharvester;
3 3 import com.google.gson.JsonElement;
4 4 import com.google.gson.JsonObject;
5 5 import com.google.gson.JsonParser;
  6 +import dataproviders.DataProviderLaReferencia;
6 7 import org.openqa.selenium.By;
7 8 import org.openqa.selenium.support.ui.FluentWait;
8 9 import org.openqa.selenium.support.ui.Wait;
... ... @@ -19,12 +20,12 @@ import java.util.concurrent.TimeUnit;
19 20 import static org.testng.Assert.assertTrue;
20 21  
21 22 public class TestIndexHistoricLrharvester extends TestBase {
22   - String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
  23 + String sURL = baseUrl + "/public/getRunningStatus";
23 24  
24 25  
25   - @Test
26   - public void testIndexHistoric() throws Exception {
27   - driver.get("http://dev6.rcaap.pt/backend/home#");
  26 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  27 + public void testIndexHistoric(String baseUrl) throws Exception {
  28 + driver.get(baseUrl);
28 29 driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
29 30 acceptNextAlert = true;
30 31 driver.findElement(By.xpath("(//a[contains(text(),'Indexar histórico no Portal')])[2]")).click();
... ...
src/test/java/testng/lrharvester/TestIndexVufindLrharvester.java
... ... @@ -3,6 +3,7 @@ package testng.lrharvester;
3 3 import com.google.gson.JsonElement;
4 4 import com.google.gson.JsonObject;
5 5 import com.google.gson.JsonParser;
  6 +import dataproviders.DataProviderLaReferencia;
6 7 import org.openqa.selenium.By;
7 8 import org.openqa.selenium.support.ui.FluentWait;
8 9 import org.openqa.selenium.support.ui.Wait;
... ... @@ -19,12 +20,12 @@ import java.util.concurrent.TimeUnit;
19 20 import static org.testng.Assert.assertTrue;
20 21  
21 22 public class TestIndexVufindLrharvester extends TestBase {
22   - String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
  23 + String sURL = baseUrl + "/public/getRunningStatus";
23 24  
24 25  
25   - @Test
26   - public void testIndexVufindFull() throws Exception {
27   - driver.get("http://dev6.rcaap.pt/backend/home#");
  26 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  27 + public void testIndexVufindFull(String baseUrl) throws Exception {
  28 + driver.get(baseUrl);
28 29 driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
29 30 acceptNextAlert = true;
30 31 driver.findElement(By.xpath("(//a[contains(text(),'Indexación Vufind (full)')])[2]")).click();
... ... @@ -78,7 +79,17 @@ public class TestIndexVufindLrharvester extends TestBase {
78 79 JsonObject response= rootobj.get("response").getAsJsonObject();
79 80 int numFound = response.get("numFound").getAsInt();
80 81  
81   - url = new URL("http://dev6.rcaap.pt/backend/public/lastGoodKnowSnapshotByNetworkID/4");
  82 + url = new URL("http://dev6.rcaap.pt/backend/private/networks?count=1&filter[teste]=CC&page=1");
  83 + request = url.openConnection();
  84 + request.connect();
  85 + jp = new JsonParser();
  86 + root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
  87 + rootobj = root.getAsJsonObject();
  88 + JsonObject network = rootobj.get("networks").getAsJsonObject();
  89 + String networkID = network.get("networkID").getAsString();
  90 +
  91 +
  92 + url = new URL("http://dev6.rcaap.pt/backend/public/lastGoodKnowSnapshotByNetworkID/"+ networkID);
82 93 request = url.openConnection();
83 94 request.connect();
84 95 jp = new JsonParser(); //from gson
... ...
src/test/java/testng/lrharvester/TestLoginLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import dataproviders.DataProviderLaReferencia;
3 4 import org.openqa.selenium.By;
4 5 import org.testng.annotations.Test;
5 6 import testng.rcaap.TestBase;
6 7  
7 8 public class TestLoginLrharvester extends TestBase {
8 9  
9   - @Test
10   - public void testLogin() throws Exception {
11   - driver.get("http://dev6.rcaap.pt/backend");
  10 +
  11 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  12 + public void testLogin(String baseUrl) throws Exception {
  13 + driver.get(baseUrl);
12 14 driver.findElement(By.id("username")).click();
13 15 driver.findElement(By.id("username")).sendKeys("adminrcaap");
14 16 driver.findElement(By.id("password")).click();
... ...
src/test/java/testng/lrharvester/TestTransformValidateFullLrharvester.java
... ... @@ -4,6 +4,7 @@ import com.google.gson.JsonArray;
4 4 import com.google.gson.JsonElement;
5 5 import com.google.gson.JsonObject;
6 6 import com.google.gson.JsonParser;
  7 +import dataproviders.DataProviderLaReferencia;
7 8 import org.openqa.selenium.By;
8 9 import org.openqa.selenium.support.ui.FluentWait;
9 10 import org.openqa.selenium.support.ui.Wait;
... ... @@ -20,13 +21,13 @@ import java.util.concurrent.TimeUnit;
20 21 import static org.testng.Assert.assertTrue;
21 22  
22 23 public class TestTransformValidateFullLrharvester extends TestBase {
23   - String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
  24 + String sURL = baseUrl + "/public/getRunningStatus";
24 25  
25 26  
26 27  
27   - @Test
28   - public void testTransformValidateFull() throws Exception {
29   - driver.get("http://dev6.rcaap.pt/backend/home#");
  28 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  29 + public void testTransformValidateFull(String baseUrl) throws Exception {
  30 + driver.get(baseUrl);
30 31 driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
31 32 acceptNextAlert = true;
32 33 driver.findElement(By.xpath("(//a[contains(text(),'Validación/Transformación (full)')])[2]")).click();
... ... @@ -69,7 +70,7 @@ public class TestTransformValidateFullLrharvester extends TestBase {
69 70 private boolean isTransformed() throws IOException {
70 71  
71 72  
72   - URL url = new URL("http://dev6.rcaap.pt/backend/public/listSnapshotsByNetworkAcronym/teste");
  73 + URL url = new URL(baseUrl + "/public/listSnapshotsByNetworkAcronym/teste");
73 74 URLConnection request = url.openConnection();
74 75 request.connect();
75 76  
... ...