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 diff is collapsed.
<?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
This diff is collapsed.
package ee.ria.riha.pages;
import ee.ria.riha.context.ScenarioContext;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static ee.ria.riha.Timeouts.DISPLAY_ELEMENT_TIMEOUT;
import static ee.ria.riha.Timeouts.TABLE_SORT_TIMEOUT;
public class InfosystemsPage extends BasePage {
@FindBy(xpath = "//main[@id='content']/app-browser-list/section/div[2]/a")
private WebElement detailedSearchLink;
@FindBy(id = "owner-name-input")
private WebElement ownerInput;
@FindBy(id = "name-input")
private WebElement nameInput;
@FindBy(id = "topics-input")
private WebElement topicsInput;
@FindBy(id = "info-systems-table")
private WebElement infosystemsTable;
public InfosystemsPage(ScenarioContext scenarioContext) {
super(scenarioContext);
PageFactory.initElements(driver, this);
}
public List<String> getFoundInfosystemsTopics() {
waitForLoading();
List<String> topics = new ArrayList<>();
List<WebElement> tableRows = infosystemsTable.findElements(By.tagName("tr"));
tableRows.forEach(row -> {
if (row.findElements(By.className("topics")).size() > 0) {
topics.add(row.findElement(By.className("topics")).findElements(By.tagName("button")).stream().map(WebElement::getText).collect(Collectors.joining(",")));
}
});
return topics;
}
public List<String> getFoundInfosystemsShortName() {
waitForLoading();
List<String> sortNames = new ArrayList<>();
List<WebElement> tableRows = infosystemsTable.findElements(By.tagName("tr"));
tableRows.forEach(row -> {
sortNames.add(row.findElement(By.xpath("//td[2]")).findElement(By.tagName("a")).getText());
});
return sortNames;
}
public void openDetailedSearchForm() {
waitForLoading();
detailedSearchLink.click();
}
public String getTopicInputText() {
waitForLoading();
return topicsInput.getAttribute("value");
}
public String getOwnerInputText() {
return ownerInput.getAttribute("value");
}
public String getNameInputText() {
return nameInput.getAttribute("value");
}
public void searchByOwnerNameAndTopic(String owner, String name, String topic) {
ownerInput.sendKeys(owner);
nameInput.sendKeys(name);
topicsInput.sendKeys(topic);
topicsInput.sendKeys(Keys.RETURN);
waitForLoading();
}
private void waitForLoading() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, infosystemsTable, "info-systems-table");
wait.sleep(TABLE_SORT_TIMEOUT);
}
}
package ee.ria.riha.pages;
import ee.ria.riha.context.ScenarioContext;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class LoginPage extends BasePage {
@FindBy(css = ".c-tab-login__nav-label > .icon-mobile-id")
private WebElement mobiilIdTab;
@FindBy(id = "mid-personal-code")
private WebElement isikukoodInput;
@FindBy(id = "mid-phone-number")
private WebElement telefoninumberInput;
@FindBy(css = "tr:nth-child(3) .c-btn")
private WebElement jatkanButton;
public LoginPage(ScenarioContext scenarioContext) {
super(scenarioContext);
PageFactory.initElements(driver, this);
}
public void selectMobiilIdTab() {
mobiilIdTab.click();
}
public void enterIsikukoodAndTelefoninumber(String personalCode, String phoneNumber) {
isikukoodInput.sendKeys(personalCode);
telefoninumberInput.sendKeys(phoneNumber);
jatkanButton.click();
}
}
package ee.ria.riha.pages;
import ee.ria.riha.context.ScenarioContext;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import java.util.ArrayList;
import java.util.List;
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.LAST_INFOSYSTEM_NUMBER;
import static ee.ria.riha.context.ScenarioContext.SEARCH_TEXT_KEY;
public class MyInfosystemsPage extends BasePage {
@FindBy(xpath = "//main[@id='content']/app-producer-list/section/div[2]/a[4]")
private WebElement detailedSearchLink;
@FindBy(id = "search-text-input")
private WebElement searchTextInput;
@FindBy(id = "topics-input")
private WebElement topicsInput;
@FindBy(id = "name-input")
private WebElement nameInput;
@FindBy(id = "short-name-input")
private WebElement shortNameInput;
@FindBy(id = "purpose-textarea")
private WebElement purposeInput;
@FindBy(css = ".table-responsive > .btn")
private WebElement createNewLink;
@FindBy(xpath = "//button[@type='submit']")
private WebElement submitButton;
@FindBy(id = "infosystems-table")
private WebElement infosystemsTable;
@FindBy(xpath = "//table[@id='infosystems-table']/thead/th/app-sort-button/button")
private WebElement sortByShortNameButton;
public MyInfosystemsPage(ScenarioContext scenarioContext) {
super(scenarioContext);
PageFactory.initElements(driver, this);
}
public void openDetailedSearchForm() {
detailedSearchLink.click();
}
public void searchByTopic(String topic) {
topicsInput.sendKeys(topic);
topicsInput.sendKeys(Keys.RETURN);
}
public List<String> getFoundInfosystemsTopics() {
waitForLoading();
List<String> topics = new ArrayList<>();
List<WebElement> tableRows = infosystemsTable.findElements(By.tagName("tr"));
tableRows.forEach(row -> {
topics.add(row.findElement(By.className("topics")).findElements(By.tagName("button")).stream().map(WebElement::getText).collect(Collectors.joining(",")));
});
return topics;
}
public void goToInfosystemPage(String infosystem) {
driver.findElement(By.linkText(infosystem)).click();
}
public void goToCreateNewInfosystemPage() {
wait.forElementToBeDisplayed(DISPLAY_ELEMENT_TIMEOUT, createNewLink, "createNewLink");
createNewLink.click();
}
public void enterNameShortNameAndPurpose(String namePrefix, String shortNamePrefix, String purpose) {
String lastCreatedInfosystemNumber = scenarioContext.getFromContext(LAST_INFOSYSTEM_NUMBER);
int i = Integer.parseInt(lastCreatedInfosystemNumber);
i++;
nameInput.sendKeys(namePrefix + " " + i);
shortNameInput.sendKeys(shortNamePrefix + "-" + i);
purposeInput.sendKeys(purpose);
submitButton.click();
}
public void enterSearchText(String text) {
waitForLoading();
scenarioContext.saveToContext(SEARCH_TEXT_KEY, text);
searchTextInput.sendKeys(text);
searchTextInput.sendKeys(Keys.RETURN);
waitForLoading();
}
public void sortByShortNameDesc() {
sortByShortNameButton.click(); //asc
waitForLoading();
sortByShortNameButton.click(); //desc
waitForLoading();
}
public void saveFirstFoundInfosystemShortNameToScenarioContext() {
WebElement firstRow = infosystemsTable.findElement(By.xpath("//tr[1]"));