Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pn 9164 #154

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public DisserviziAppPAPage(WebDriver driver) {
List<WebElement> statusList;


@FindBy(css = "[data-testid='download-legal-fact']")
List<WebElement> attestazioniFile;

@FindBy(xpath = "//span[contains(text(), 'Risolto')]")
List<WebElement> stato;

public void waitLoadStatoDellaPiattaformaPage() {
try {
By disserviziPageTitle = By.id("Stato della piattaforma-page");
Expand Down Expand Up @@ -153,4 +159,45 @@ public void checkDisserviziDisponibili() {
Assert.fail("Non si visualizza un record in elenco relativo ad un disservizio disponibile");
}
}
public void checkDisserviziRisolto() {
try {
aggiornamentoPagina();
List<WebElement> disserviziTableRow = driver.findElements(By.cssSelector("[aria-rowindex='1']"));
if (!disserviziTableRow.isEmpty()) {
for (WebElement disserviziRow : disserviziTableRow) {
List<WebElement> disserviziColumns = disserviziRow.findElements(By.xpath("//td[@data-testid='tableDowntimeLog.row.cell']"));
if (!disserviziColumns.isEmpty()) {
// check if the columns are not empty
for (WebElement disserviziColumn : disserviziColumns) {
if (disserviziColumn.getText().contains(",")) {
logger.info("Si visualizza data di inizio e data di fine'");
}

if (attestazioniFile.get(0).isDisplayed()) {
logger.info("Si visualizza bottone scarica l'attestazione'");
}
if (stato.get(0).isDisplayed()) {
logger.info("Si visualizza un record in elenco relativo ad un disservizio Risolto");
return;
}
}
}
}
}
logger.error("Non si visualizza un record in elenco relativo ad un disservizio ancora in corso");
Assert.fail("Non si visualizza un record in elenco relativo ad un disservizio ancora in corso");
} catch (TimeoutException e) {
logger.error("Non si visualizza un record in elenco relativo ad un disservizio ancora in corso con errore:" + e.getMessage());
Assert.fail("Non si visualizza un record in elenco relativo ad un disservizio ancora in corso con errore" + e.getMessage());
}
}

public void clickLinkAttestazioniOpponibileDisservizi(int numeroLinkAttestazioniOpponibile) {
if (attestazioniFile.get(numeroLinkAttestazioniOpponibile).isDisplayed()) {
attestazioniFile.get(numeroLinkAttestazioniOpponibile).click();
} else {
this.js().executeScript("arguments[0].scrollIntoView(true);", attestazioniFile.get(numeroLinkAttestazioniOpponibile));
attestazioniFile.get(numeroLinkAttestazioniOpponibile).click();
}
}
}
95 changes: 95 additions & 0 deletions src/main/java/it/pn/frontend/e2e/utility/DownloadFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import it.pn.frontend.e2e.common.BasePage;
import it.pn.frontend.e2e.listeners.Hooks;
import it.pn.frontend.e2e.listeners.NetWorkInfo;
import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
Expand Down Expand Up @@ -35,6 +38,8 @@ public void download(String urlLink, File fileLoc, boolean healdess) {
HttpURLConnection http = (HttpURLConnection)url.openConnection();
double filesize = (double)http.getContentLengthLong();

http.setRequestProperty("Authorization", getBearerSessionToken());

BufferedInputStream input = new BufferedInputStream(http.getInputStream());
FileOutputStream ouputfile = new FileOutputStream(fileLoc);
BufferedOutputStream bufferOut = new BufferedOutputStream(ouputfile, 1024);
Expand Down Expand Up @@ -68,6 +73,55 @@ public void download(String urlLink, File fileLoc, boolean healdess) {
}
}


public void downloadAttestazioneDisservizi(String urlLink, File fileLoc, boolean headless) throws IOException {
if (headless) {
try {
byte[] buffer = new byte[1024];
double totalDownload = 0.00;
int readBytes; // Stores the number of bytes read in each iteration.
double percentOfDownload = 0.00;

URL url = new URL(urlLink);
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setRequestProperty("Authorization", getBearerSessionToken());
double fileSize = (double) http.getContentLengthLong();

BufferedInputStream input = new BufferedInputStream(http.getInputStream());
FileOutputStream output = new FileOutputStream(fileLoc);
BufferedOutputStream bufferOut = new BufferedOutputStream(output, 1024);

while ((readBytes = input.read(buffer, 0, 1024)) >= 0) {
// Writing the content onto the file.
bufferOut.write(buffer, 0, readBytes);
// TotalDownload is the total bytes written onto the file.
totalDownload += readBytes;
// Calculating the percentage of download.
percentOfDownload = (totalDownload * 100) / fileSize;
// Formatting the percentage up to 2 decimal points.
String percent = String.format("%.2f", percentOfDownload);
System.out.println("Downloaded " + percent + "%");
}

System.out.println("Your download is now complete.");

// Closing streams
bufferOut.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
URL url = new URL(urlLink);
FileUtils.copyURLToFile(url, fileLoc, 1000, 1000);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}


public void controlloDownload(String path, int numberOfFile){
File directory = new File(path);

Expand Down Expand Up @@ -122,4 +176,45 @@ public String getUrl(String urlChiamata) {
}
return url;
}

public String getLegalFactId() {
try {
URL url = new URL("https://webapi.test.notifichedigitali.it/downtime/v1/history?fromTime=1900-01-01T00%3A00%3A00Z&toTime=2024-03-28T10%3A38%3A50.251Z&functionality=NOTIFICATION_CREATE&functionality=NOTIFICATION_VISUALIZATION&functionality=NOTIFICATION_WORKFLOW&page=0&size=10");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", getBearerSessionToken() );

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

JSONObject jsonResponse = new JSONObject(response.toString());
JSONArray resultArray = jsonResponse.getJSONArray("result");
if (!resultArray.isEmpty()) {
JSONObject firstResult = resultArray.getJSONObject(0);
return firstResult.getString("legalFactId");
}
} catch (Exception e) {
throw new RuntimeException("Failed to fetch legalFactId",e);
}
return null;
}

private String getBearerSessionToken() {
List<NetWorkInfo> netWorkInfos = Hooks.netWorkInfos;
String bearerToken = "";
for (NetWorkInfo netWorkInfo : netWorkInfos) {
String variabileAmbiente = System.getProperty("environment");
String urlChiamata = "https://webapi." + variabileAmbiente + ".notifichedigitali.it/delivery/notifications/received?";
if (netWorkInfo.getRequestUrl().contains(urlChiamata)) {
bearerToken = netWorkInfo.getAuthorizationBearer();
}
}
return bearerToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import it.pn.frontend.e2e.common.DettaglioNotificaSection;
import it.pn.frontend.e2e.listeners.Hooks;
import it.pn.frontend.e2e.pages.destinatario.personaFisica.AccediAPiattaformaNotifichePage;
import it.pn.frontend.e2e.pages.mittente.DisserviziAppPAPage;
import it.pn.frontend.e2e.utility.DownloadFile;
import it.pn.frontend.e2e.utility.DownloadFile;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class DisserviziAppPATest {
private static final Logger logger = LoggerFactory.getLogger("DisserviziAppPATest");
private final WebDriver driver = Hooks.driver;
Expand Down Expand Up @@ -40,6 +47,41 @@ public void siVisualizzaUnRecordInElencoRelativoAdUnDisservizioAncoraInCorso() {
disserviziAppPAPage.checkDisserviziInCorso();
}

@And("Si visualizza un record in elenco relativo ad un disservizio risolto")
public void siVisualizzaUnRecordInElencoRelativoAdUnDisservizioRisolto() {
logger.info("Si visualizza un record in elenco relativo ad un disservizio risolto");
disserviziAppPAPage.checkDisserviziRisolto();
}

@And("Si scarica attestazione opponibile, e si controlla che il download sia avvenuto")
public void siScaricaAttestazioneOpponibileDisservizi() throws IOException {
logger.info("Si scarica attestazione opponibile");
DownloadFile downloadFile = new DownloadFile(this.driver);
String workingDirectory = System.getProperty("user.dir");
File pathCartella = new File(workingDirectory + "/src/test/resources/dataPopulation/downloadFileNotifica/destinatario/personaGiuridica");

boolean headless = System.getProperty("headless").equalsIgnoreCase("true");
if (!downloadFile.controlloEsistenzaCartella(pathCartella)) {
pathCartella.mkdirs();
}
disserviziAppPAPage.clickLinkAttestazioniOpponibileDisservizi(0);
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
String legalFactId = downloadFile.getLegalFactId();
String urlFileAttestazioneOpponibile ="https://webapi.test.notifichedigitali.it/downtime/v1/legal-facts/" + legalFactId;

File file = new File(workingDirectory + "/src/test/resources/dataPopulation/downloadFileNotifica/destinatario/notificaN" + 0 + ".pdf");
downloadFile.downloadAttestazioneDisservizi(urlFileAttestazioneOpponibile, file, headless);
if (!headless) {
disserviziAppPAPage.goBack();
}

downloadFile.controlloDownload(workingDirectory + "/src/test/resources/dataPopulation/downloadFileNotifica/destinatario", 1);
}

@And("Si visualizzano tutti i record in elenco relativi a disservizi risolti")
public void siVisualizzanoTuttiIRecordInElencoRelativiADisserviziRisolti() {
logger.info("Si visualizzano tutti i record in elenco relativi a disservizi risolti");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: La persona giuridica visualizza i disservizi della applicazione

@TestSuite
@TA_PG_VisualizzaDisservizioRisolto
@DisserviziAppPG
@PG

Scenario: PN-9164 - Il persona giuridica loggato visualizza lo stato dei disservizi
Given PG - Si effettua la login tramite token exchange come "delegante", e viene visualizzata la dashboard
And Nella dashboard persona giuridica clicca su disservizi app
And Si visualizza correttamente la Pagina dello Stato della piattaforma
And Si visualizzano correttamente i dati sullo stato della piattaforma
And Si visualizza storico disservizi
And Si visualizza un record in elenco relativo ad un disservizio risolto
And Si scarica attestazione opponibile, e si controlla che il download sia avvenuto
And Logout da portale persona giuridica