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

Web GUI testing #50

Merged
merged 6 commits into from
Nov 12, 2016
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ overlays
**/webapp/resources/thrift/*
*~*
*.jar
**/build
!**/3dparty/*.jar
**/.idea/**
!**/.idea/misc.xml
Expand Down
4 changes: 4 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ before_install:
#fake random with urandom (do not repeat it on your own computer)
- sudo rm /dev/random
- sudo mknod /dev/random c 1 9
# for gui tests
- export CHROME_BIN=/usr/bin/google-chrome
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sudo apt-get install -y libappindicator1 fonts-liberation
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- sudo dpkg -i google-chrome*.deb

install:
#install and run tests
- mvn install -P travis
- cd ui-testing
- mvn install -DskipTests
- cd ..

script:
#run checkstyle
Expand All @@ -38,6 +48,7 @@ script:
- java -jar checkstyle-7.0-all.jar -c Travis/checkstyle/checkstyle.xml db-services/db-diagram-service/src
- java -jar checkstyle-7.0-all.jar -c Travis/checkstyle/checkstyle.xml db-services/db-robot-store-service/src
- java -jar checkstyle-7.0-all.jar -c Travis/checkstyle/checkstyle.xml db-services/db-user-service/src
- java -jar checkstyle-7.0-all.jar -c Travis/checkstyle/checkstyle.xml ui-testing/src

#run services
- cd db-services
Expand Down Expand Up @@ -68,5 +79,9 @@ script:

- ../Travis/callTomcat.sh

- cd ../ui-testing
- mvn test -P travis &
- sleep 30

notifications:
slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E
6 changes: 3 additions & 3 deletions Travis/callTomcat.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
iter=1
all=120
until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:8080/auth | grep '302 Found'`" != "" ];
until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:"${1:-"8080"}"/auth | grep '302 Found'`" != "" ];
do
if [ "$iter" -lt "$all" ]
then
Expand All @@ -16,7 +16,7 @@ done
echo "auth-service found"
iter=1
all=120
until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:8082/dashboard | grep '302 Found'`" != "" ];
until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:"${2:-"8082"}"/dashboard | grep '302 Found'`" != "" ];
do
if [ "$iter" -lt "$all" ]
then
Expand All @@ -31,7 +31,7 @@ done
echo "dashboard-service found"
iter=1
all=120
until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:8081/editor | grep '302 Found'`" != "" ];
until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:"${3:-"8081"}"/editor | grep '302 Found'`" != "" ];
do
if [ "$iter" -lt "$all" ]
then
Expand Down
93 changes: 93 additions & 0 deletions ui-testing/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?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>

<groupId>groupId</groupId>
<artifactId>UI-testing</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>wmp</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<scanner>true</scanner> <!-- default -->
</properties>

<build>

<resources>
<!-- Used to export maven variables to property files -->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
</configuration>
</plugin>

<!-- compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution><!-- Run our version calculation script -->
<id>Check services</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<skip>${scanner}</skip>
<executable>${basedir}/../Travis/callTomcat.sh</executable>
<arguments>
<argument>8080</argument>
<argument>8080</argument>
<argument>8080</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>


</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>1.4.10</version>
</dependency>

</dependencies>
</project>
25 changes: 25 additions & 0 deletions ui-testing/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" strict="true" name="XMLConfigTest"
packages="org.apache.logging.log4j.test">
<Appenders>
<Appender type="Console" name="Main">
<Layout type="PatternLayout" pattern="%d{HH:mm:ss} %C.%M -- %m%n%ex%n"/>
</Appender>
</Appenders>

<Loggers>
<logger name="org.hibernate" level="ERROR" additivity="false">
<AppenderRef ref="Main"/>
</logger>

<logger name="org.springframework" level="ERROR" additivity="false">
<AppenderRef ref="Main"/>
</logger>

<!-- Root Logger -->
<Root level="INFO">
<AppenderRef ref="Main"/>
</Root>
</Loggers>

</Configuration>
1 change: 1 addition & 0 deletions ui-testing/src/main/resources/services.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
accessDashboardUri=http://localhost:${port.dashboard}${path.dashboard}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.qreal.wmp.uitesting.auth;

import com.codeborne.selenide.WebDriverRunner;
import io.github.bonigarcia.wdm.ChromeDriverManager;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import static com.codeborne.selenide.Condition.appear;
import static com.codeborne.selenide.Condition.exist;
import static com.codeborne.selenide.Selectors.byText;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;

public class AuthDashboardTest {

private static String dashboardUrl;

private static WebDriver driver;

/**
* Setup ChromeDriverManager and load correct urls from .properties file.
*/
@BeforeClass
public static void setUpClass() {
ChromeDriverManager.getInstance().setup();
final String resourceName = "services.properties";
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Properties props = new Properties();
try (InputStream resourceStream = loader.getResourceAsStream(resourceName)) {
props.load(resourceStream);
} catch (IOException e) {
e.printStackTrace();
}
dashboardUrl = props.getProperty("accessDashboardUri");
}

/**
* Try to open dashboard page.
* Should be redirected to auth page.
*/
@Before
public void openAuthPage() {
driver = new ChromeDriver();
WebDriverRunner.setWebDriver(driver);
open(dashboardUrl);
$(byText("Sign in to continue to Auth")).shouldBe(exist);
$(byText("Dashboard")).shouldNotBe(exist);
}

/**
* Try to login with correct username and password.
* Should access and redirect to dashboard
*/
@Test
public void userCanLoginByUsername() {
$(By.name("username")).setValue("123");
$(By.name("password")).setValue("123");
$("[type=\"submit\"]").click();
$(byText("Dashboard")).waitUntil(appear, 50000);
}

/**
* Try to login with random username and password.
* An error must be shown
*/
@Test
public void userWrongAuth() {
$(byText("Password or login wrong")).shouldNotBe(exist);
char[] alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray();
String wrongLogin = RandomStringUtils.random(20, alphabet);
String wrongPassword = RandomStringUtils.random(20, alphabet);
$(By.name("username")).setValue(wrongLogin);
$(By.name("password")).setValue(wrongPassword);
$("[type=\"submit\"]").click();
$(byText("Password or login wrong")).shouldBe(exist);
}

@After
public void logout() {
driver.close();
}

}
Loading