Commit cfd5beb1 authored by Kristjan Kruus's avatar Kristjan Kruus

Merge pull request #38 in RIHA/riha-browser from...

Merge pull request #38 in RIHA/riha-browser from release/RIHAKB-880-riha-tootejuhina-soovin-et-rihapisara-develop-harust-oleks-tehtud-riha-7.6 to master

* commit 'a1ae715f': (90 commits)
  producer-edit-documents.component.html edited online with Bitbucket
  producer-details-legislations.component.html edited online with Bitbucket
  producer-details-documents.component.html edited online with Bitbucket
  login-link-component.html edited online with Bitbucket
  producer-details-issues.component.html edited online with Bitbucket
  producer-edit-documents.component.html edited online with Bitbucket
  producer-edit-objects.component.html edited online with Bitbucket
  producer-details-objects.component.html edited online with Bitbucket
  producer-edit-objects.component.html edited online with Bitbucket
  producer-details-security.component.html edited online with Bitbucket
  producer-details-legislations.component.html edited online with Bitbucket
  producer-details-documents.component.html edited online with Bitbucket
  producer-edit-documents.component.html edited online with Bitbucket
  approver-issue-details.component.html edited online with Bitbucket
  approver-issue-details.component.html edited online with Bitbucket
  approver-issue-details.component.html edited online with Bitbucket
  environment.service.ts edited online with Bitbucket
  riha-navbar.component.ts edited online with Bitbucket
  environment.service.ts edited online with Bitbucket
  riha-navbar.component.ts edited online with Bitbucket
  ...
parents 279e4d64 a1ae715f
image: riha-test-env
variables:
ARTIFACT_NAME: "ROOT.war"
stages:
- build
- deploy
build:
stage: build
script:
- ./build.sh
artifacts:
paths:
- backend/target/*.war
expire_in: 1 mos
tags:
- riha
deploy_demo:
stage: deploy
script:
- echo "$SSH_PRIVATE_KEY" > id_rsa
- chmod 700 id_rsa
- mkdir $HOME/.ssh
- echo "$SSH_HOST_KEY" > $HOME/.ssh/known_hosts
- scp -i id_rsa backend/target/*.war deployer@$SSH_HOST:$DEPLOYMENT_DIR/$ARTIFACT_NAME
environment:
name: demo
when: manual
tags:
- riha
\ No newline at end of file
language: java
jdk:
- oraclejdk8
before_script:
- npm install karma-cli karma jasmine-core karma-jasmine karma-junit-reporter karma-jasmine-jquery karma-jasmine-ajax karma-coverage karma-phantomjs2-launcher coffee-script@1.8.0 bower-installer@0.8.4
script: ./test.sh && ./build.sh
This source diff could not be displayed because it is too large. You can view the blob instead.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>autotest</artifactId>
<name>Autotest</name>
<description>Automated UI tests</description>
<parent>
<artifactId>browser</artifactId>
<groupId>ee.ria.riha</groupId>
<version>7.6</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package ee.ria.riha;
public final class Timeouts {
public static final int TABLE_SORT_TIMEOUT = 2000;
public static final int DISPLAY_ELEMENT_TIMEOUT = 15;
}
package ee.ria.riha.context;
import java.util.HashMap;
import java.util.Map;
public class ScenarioContext {
public static final String APP_URL_KEY = "appUrl";
public static final String SEARCH_TEXT_KEY = "searchText";
public static final String NAME_KEY = "name";
public static final String SHORT_NAME_KEY = "shortName";
public static final String HOMEPAGE_KEY = "homepage";
public static final String PURPOSE_KEY = "purpose";
public static final String LAST_INFOSYSTEM_NUMBER = "lastInfosystemNumber";
public static final String DEFAULT_APP_URL = "https://riha-browser-ik.ci.kit";
private final Map<String, String> context = new HashMap<>();
public ScenarioContext() {
String url = System.getProperty("url");
if (url == null) {
url = DEFAULT_APP_URL;
}
context.put(APP_URL_KEY, url);
}
public void saveToContext(String key, String value) {
context.put(key, value);
}
public String getFromContext(String key) {
return context.get(key);
}
public void clear() {
context.clear();
}
}
package ee.ria.riha.driver;
import ee.ria.riha.pages.PageFactory;
import io.cucumber.java.Before;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Setup {
public static WebDriver driver;
public static PageFactory pageFactory;
@Before
public void init() {
String browser = System.getProperty("browser");
if (browser == null) {
browser = "chrome";
}
switch (browser) {
case "chrome":
WebDriverManager.chromedriver().setup();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("start-maximized");
driver = new ChromeDriver(chromeOptions);
break;
case "firefox":
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
driver.manage().window().maximize();
break;
default:
throw new IllegalArgumentException("Browser \"" + browser + "\" isn't supported.");
}
pageFactory = new PageFactory();
}
}
package ee.ria.riha.driver;
import io.cucumber.core.api.Scenario;
import io.cucumber.java.After;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public class TearDown {
private WebDriver driver;
public TearDown() {
this.driver = Setup.driver;
}
@After
public void quitDriver(Scenario scenario) {
if (scenario.isFailed()) {
saveScreenshotsForScenario(scenario);
}
this.driver.quit();
}
private void saveScreenshotsForScenario(final Scenario scenario) {
final byte[] screenshot = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
}
package ee.ria.riha.driver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
public class Wait {
private WebDriver driver;
public Wait(WebDriver driver) {
this.driver = driver;
}
private void waitUntilCondition(ExpectedCondition condition, String timeoutMessage, int timeout) {
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.withMessage(timeoutMessage);
wait.until(condition);
}
public void forElementToBeDisplayed(int timeout, WebElement webElement, String webElementName) {
ExpectedCondition<WebElement> condition = ExpectedConditions.visibilityOf(webElement);
String timeoutMessage = webElementName + " wasn't displayed after " + Integer.toString(timeout) + " seconds.";
waitUntilCondition(condition, timeoutMessage, timeout);
}
public void forPresenceOfElements(int timeout, By elementLocator, String elementName) {
ExpectedCondition<List<WebElement>> condition = ExpectedConditions.presenceOfAllElementsLocatedBy(elementLocator);
String timeoutMessage = elementName + " elements were not displayed after " + Integer.toString(timeout) + " seconds.";
waitUntilCondition(condition, timeoutMessage, timeout);
}
public void sleep(int timeout) {
try {
Thread.sleep(timeout);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
package ee.ria.riha.pages;
import ee.ria.riha.context.ScenarioContext;
import ee.ria.riha.driver.Setup;
import ee.ria.riha.driver.Wait;
import org.openqa.selenium.WebDriver;
public class BasePage {
protected WebDriver driver;
protected Wait wait;
protected ScenarioContext scenarioContext;
public BasePage(ScenarioContext scenarioContext) {
this.driver = Setup.driver;
this.wait = new Wait(driver);
this.scenarioContext = scenarioContext;
}
public String getCurrentUrl() {
return driver.getCurrentUrl();
}
public ScenarioContext getScenarioContext() {
return scenarioContext;
}
}
package ee.ria.riha.pages;
import ee.ria.riha.context.ScenarioContext;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import static ee.ria.riha.Timeouts.DISPLAY_ELEMENT_TIMEOUT;
public class HomePage extends BasePage {
@FindBy(xpath = "//img[@src='assets/images/base/RIHA.png']")
private WebElement logo;
@FindBy(css = ".btn > span:nth-child(1)")
private WebElement loginButton;
@FindBy(css = ".card:nth-child(2) .btn")
private WebElement goToMyInfosystemsPageButton;
@FindBy(css = ".nav-item:nth-child(2) > .nav-link")
private WebElement goToInfosystemsPageLink;
@FindBy(tagName = "ngb-modal-window")
private WebElement modalContainer;
public HomePage(ScenarioContext scenarioContext) {
super(scenarioContext);
PageFactory.initElements(driver, this);
}
public void goToPage(String path) {
String url = scenarioContext.getFromContext(ScenarioContext.APP_URL_KEY);
driver.get(url + path);
checkLogoDisplay();
}
public void checkLogoDisplay() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, this.logo, "Logo");
}
public String getTitle() {
return driver.getTitle();
}
public String getLoggedInUsersName() {
return this.driver.findElement(By.cssSelector(".right a")).getText();
}
public void selectSecondOrganization() {
wait.forPresenceOfElements(25, By.tagName("ngb-modal-window"), "modal");
modalContainer.findElement(By.cssSelector("tr:nth-child(2) > td")).click();
}
public void selectOrganization(String organization) {
driver.findElement(By.cssSelector(".right a")).click();
wait.forPresenceOfElements(2, By.tagName("ngb-modal-window"), "modal");
modalContainer.findElement(By.xpath("//td[contains(.,'" + organization +"')]")).click();
}
public void goToLoginPage() {
loginButton.click();
}
public void goToMyInfosystemsPage() {
goToMyInfosystemsPageButton.click();
}
public void goToInfosystemsPage() {
goToInfosystemsPageLink.click();
}
}
\ No newline at end of file
package ee.ria.riha.pages;
import ee.ria.riha.context.ScenarioContext;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;
import java.util.stream.Collectors;
import static ee.ria.riha.Timeouts.DISPLAY_ELEMENT_TIMEOUT;
import static ee.ria.riha.Timeouts.TABLE_SORT_TIMEOUT;
import static ee.ria.riha.context.ScenarioContext.*;
import static org.openqa.selenium.Keys.BACK_SPACE;
import static org.openqa.selenium.Keys.RETURN;
public class InfosystemPage extends BasePage {
@FindBy(xpath = "//div[@id='uldkirjeldus']/app-producer-details-general/section/div[2]/div[2]/p")
private WebElement purposeP;
@FindBy(xpath = "//div[@id='uldkirjeldus']/app-producer-details-general/section/div[2]/h1")
private WebElement nameDiv;
@FindBy(xpath = "//div[@id='uldkirjeldus']/app-producer-details-general/section/div[2]/h2")
private WebElement shortNameDiv;
@FindBy(xpath = "//div[@id='uldkirjeldus']/app-producer-details-general/section/div[2]/div[3]/div")
private WebElement topicsDiv;
@FindBy(css = ".ng2-tags-container")
private WebElement topicTagsContainer;
@FindBy(xpath = "//div[@id='uldkirjeldus']/app-producer-details-general/section/div[2]/div[5]/div/label/a")
private WebElement homepageA;
@FindBy(xpath = "//div[@id='uldkirjeldus']/app-producer-details-general/section/div/button")
private WebElement editButton;
@FindBy(xpath = "//div[@id='kontaktid']/app-producer-details-contacts/section/div/button")
private WebElement editContactsButton;
@FindBy(xpath = "//div[@id='dokumentatsioon']/app-producer-details-tech-docs/section/div/button")
private WebElement editDocumentationButton;
@FindBy(xpath = "//div[@id='andmed']/app-producer-details-objects/section/div/button")
private WebElement editDataButton;
@FindBy(xpath = "//div[@id='kontaktid']/app-producer-details-contacts/section/div[2]/table/tr/td[2]/span")
private WebElement contactNameSpan;
@FindBy(xpath = "//div[@id='kontaktid']/app-producer-details-contacts/section/div[2]/p")
private WebElement contactsP;
@FindBy(css = ".btn-success")
private WebElement saveButton;
@FindBy(id = "name-input")
private WebElement nameInput;
@FindBy(id = "short-name-input")
private WebElement shortNameInput;
@FindBy(id = "purpose-textarea")
private WebElement purposeTextarea;
@FindBy(id = "homepage")
private WebElement homepageInput;
@FindBy(css = ".ng2-tag-input__text-input")
private WebElement topicsInput;
@FindBy(css = "app-producer-details-tech-docs table")
private WebElement techDocTable;
@FindBy(xpath = "//div[@id='andmed']/app-producer-details-objects/section/div[2]/div/table")
private WebElement dataObjectsTable;
@FindBy(xpath = "//div[@id='andmed']/app-producer-details-objects/section/div[2]/div[2]/table")
private WebElement dataUrlsTable;
@FindBy(tagName = "ngb-modal-window")
private WebElement modalContainer;
public InfosystemPage(ScenarioContext scenarioContext) {
super(scenarioContext);
PageFactory.initElements(driver, this);
}
public String getAssociatedTopicsList() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, topicsDiv, "topicsDiv");
return topicsDiv.findElements(By.tagName("button")).stream().map(WebElement::getText).collect(Collectors.joining(","));
}
public String getPurposeText() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, purposeP, "purposeP");
return purposeP.getText();
}
public String getName() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, nameDiv, "nameDiv");
return nameDiv.getText();
}
public String getShortName() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, shortNameDiv, "shortNameDiv");
return shortNameDiv.getText();
}
public String getHomepage() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, homepageA, "homepageA");
return homepageA.getText();
}
public String getContactName() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, contactNameSpan, "contactNameSpan");
return contactNameSpan.getText();
}
public void clickOnTopic(String topic) {
topicsDiv.findElements(By.tagName("button")).stream().filter(button -> button.getText().equalsIgnoreCase(topic)).findFirst().get().click();
}
public void clickEditButton() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, editButton, "editButton");
editButton.click();
}
public void clickEditContactsButton() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, editContactsButton, "editContactsButton");
editContactsButton.click();
}
public void clickSaveButton() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, saveButton, "saveButton");
saveButton.click();
}
public void changeGeneralDescription(String suffix) {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, nameInput, "nameInput");
scenarioContext.saveToContext(NAME_KEY, nameInput.getAttribute("value"));
this.nameInput.sendKeys(suffix);
scenarioContext.saveToContext(SHORT_NAME_KEY, shortNameInput.getAttribute("value"));
shortNameInput.sendKeys(suffix);
scenarioContext.saveToContext(PURPOSE_KEY, purposeTextarea.getAttribute("value"));
purposeTextarea.sendKeys(suffix);
scenarioContext.saveToContext(HOMEPAGE_KEY, homepageInput.getAttribute("value"));
homepageInput.sendKeys(suffix);
}
public void revertChangesInGeneralDescription() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, nameInput, "nameInput");
nameInput.sendKeys(BACK_SPACE);
shortNameInput.sendKeys(BACK_SPACE);
purposeTextarea.sendKeys(BACK_SPACE);
homepageInput.sendKeys(BACK_SPACE);
}
public void enterContactNameAndEmail(String name, String email) {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, modalContainer, "modalContainer");
modalContainer.findElement(By.id("name")).sendKeys(name);
modalContainer.findElement(By.id("email")).sendKeys(email);
modalContainer.findElement(By.cssSelector(".col-12 > .btn")).click();
modalContainer.findElement(By.cssSelector(".btn-success")).click();
}
public void deleteContact() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, modalContainer, "modalContainer");
modalContainer.findElement(By.cssSelector(".btn-danger")).click();
modalContainer.findElement(By.cssSelector(".btn-success")).click();
}
public String getEmptyContactsPlaceholder() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, contactsP, "contactsP");
return contactsP.getText();
}
public void enterNewTopic(String topic) {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, topicsInput, "topicsInput");
topicsInput.sendKeys(topic);
topicsInput.sendKeys(RETURN);
}
public void removeTopic(String topic) {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, topicTagsContainer, "topicTagsContainer");
WebElement topicTag = topicTagsContainer.findElements(By.tagName("tag"))
.stream()
.filter(tag -> tag.findElement(By.tagName("div")).getAttribute("aria-label").equalsIgnoreCase(topic))
.findFirst()
.get();
topicTag.findElement(By.tagName("delete-icon")).click();
}
public void clickEditDocumentationButton() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, editDocumentationButton, "editDocumentationButton");
editDocumentationButton.click();
}
public void clickOnAddNewUrlButton() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, modalContainer, "modalContainer");
modalContainer.findElement(By.cssSelector(".btn-secondary:nth-child(2)")).click();
}
public void clickEditDataButton() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, editDataButton, "editDataButton");
editDataButton.click();
}
public void enterNewTechnicalDocumentationLink(String url, String name) {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, modalContainer, "modalContainer");
modalContainer.findElement(By.id("url")).sendKeys(url);
modalContainer.findElement(By.id("linkName")).sendKeys(name);
WebElement linkTypeElement = modalContainer.findElement(By.id("linkType"));
linkTypeElement.click();
new Select(linkTypeElement).selectByValue("DOC_TYPE_OTHER");
modalContainer.findElement(By.cssSelector(".col-12 > .btn")).click();
modalContainer.findElement(By.cssSelector(".btn-success")).click();
}
public String getTechDocUrls() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, techDocTable, "techDocTable");
wait.sleep(TABLE_SORT_TIMEOUT);
return techDocTable.findElements(By.cssSelector(".name")).stream()
.map(td -> td.findElement(By.tagName("a")))
.map(WebElement::getText)
.collect(Collectors.joining(","));