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

Automated UI tests for login, create group and create notif. screens. #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
implementation 'org.knowm:sundial:2.1.1'
testCompile "org.testfx:testfx-core:4.0.13-alpha"
testCompile "org.testfx:testfx-junit:4.0.13-alpha"
testCompile group: 'org.loadui', name: 'testFx', version: '3.1.2'
compile group: 'org.apache.wink', name: 'wink-json4j', version: '1.1.2-incubating'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.6'
Expand All @@ -43,6 +44,8 @@ jar {

}
test {
systemProperty 'username', System.getProperty('username')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these credentials for? What do they correspond to?

systemProperty 'password', System.getProperty('password')
useJUnit()
maxHeapSize = '1G'
}
2 changes: 0 additions & 2 deletions src/main/java/Controller/CreateNotificationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public CreateNotificationController(ArrayList<Group> groupArrayList) {
@Override
public void initialize(URL location, ResourceBundle resources) {
progressIndicator.setVisible(false);
statusLabel.setVisible(false);

comboBox.setItems(FXCollections.observableList(groupArrayList));
comboBox.setCellFactory(new Callback<ListView<Group>, ListCell<Group>>() {
Expand Down Expand Up @@ -75,7 +74,6 @@ public void sendButtonClicked() {

if(!(titleStr.isEmpty() && messageStr.isEmpty())) {
progressIndicator.setVisible(true);
statusLabel.setVisible(true);
send_button.setDisable(true);
Group selected = comboBox.getSelectionModel().getSelectedItem();
Task<Void> task = new Task<Void>() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/Controller/LoginFormController.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ protected Void call() {
try {
if(verifyCredentials(username,password)) {
LoginCredentials.credentials = new LoginCredentials(username,password);
updateProgress(40,100);
try {
initializeFirebaseSDK();
updateProgress(80,100);
}catch (IOException e){
flag = false;
updateProgress(0,100);
Expand All @@ -93,6 +95,11 @@ protected Void call() {
flag = false;
e.printStackTrace();
updateProgress(0, 100);
updateMessage("Error: "+e.getMessage());
}
if(flag){
updateProgress(100,100);
updateMessage("Login Successful");
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Data/DatabaseCommunicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
public class DatabaseCommunicator {
private Connection c = null;
private Statement stmt = null;
static final String TABLE_GROUPS = "Groups";
static final String TABLE_NOTIFICATIONS = "Notifications";
public static final String TABLE_GROUPS = "Groups";
public static final String TABLE_NOTIFICATIONS = "Notifications";

private static final String COLUMN_NAME = "grp_name";
private static final String COLUMN_GRP_ID = "grp_id";
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fxml/CreateGroup.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<VBox.margin>
<Insets bottom="10.0" top="30.0"/>
</VBox.margin>
<Button mnemonicParsing="false" onMouseClicked="#createButtonClicked"
<Button fx:id="createButton" mnemonicParsing="false" onMouseClicked="#createButtonClicked"
prefHeight="31.0" prefWidth="117.0" text="Create"/>
<ProgressIndicator fx:id="progressIndicator" prefHeight="31.0" prefWidth="63.0" progress="0.0"
visible="false">
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fxml/MainUI.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</cursor>
</TitledPane>

<TitledPane collapsible="false" expanded="false" layoutX="10.0"
<TitledPane fx:id="createGroup_tp" collapsible="false" expanded="false" layoutX="10.0"
layoutY="10.0" onMouseClicked="#createGroupButtonClicked"
text="Create Custom Notification Groups">
<cursor>
Expand Down
89 changes: 89 additions & 0 deletions src/test/java/LaunchTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import Data.DatabaseCommunicator;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.loadui.testfx.GuiTest;
import org.testfx.util.WaitForAsyncUtils;

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

import static org.junit.Assert.assertEquals;
import static org.loadui.testfx.controls.Commons.hasText;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class LaunchTest extends GuiTest {

private Parent mainNode;
private DatabaseCommunicator dc;
@Before
public void setUp() {
dc = new DatabaseCommunicator();
dc.clearTable(DatabaseCommunicator.TABLE_GROUPS);
dc.clearTable(DatabaseCommunicator.TABLE_NOTIFICATIONS);
}

@After
public void tearDown() {
dc.clearTable(DatabaseCommunicator.TABLE_GROUPS);
dc.clearTable(DatabaseCommunicator.TABLE_NOTIFICATIONS);
dc.closeConnection();
}

@Override
protected Parent getRootNode() {
try {
mainNode = FXMLLoader.load(Launch.class.getResource("fxml/LoginPage.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
return mainNode;
}


@Test
public void stage1_loginTest () {
click("#usernameField");
type(System.getProperty("username","admin"));
click("#passwordField");
type(System.getProperty("password","admin"));
click("#loginButton");
Label statusLabel = find("#statusLabel");
waitUntil(statusLabel,hasText("Login Successful"),10);

//assertEquals(,statusLabel.getText());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove old commented out code

}

@Test
public void stage2_createGroupTest() throws TimeoutException {
click("#createGroup_tp");
click("#name_field");
type("test group");
click("#createButton");
Label status = find("#statusLabel");
WaitForAsyncUtils.waitFor(10, TimeUnit.SECONDS,()-> !status.getText().equals("Please Wait..."));
String grouplink = status.getText();
assertEquals("Group Link: ",grouplink.substring(0,12));
}

@Test
public void stage3_createNotificationTest() throws TimeoutException {
click("#createNotification_tp");
click("#title_field");
type("Test Notification");
click("#message_field");
type("This is a test notification");
click("#comboBox");
click("test group");
click("#send_button");
Label statusLabel = find("#statusLabel");
WaitForAsyncUtils.waitFor(10, TimeUnit.SECONDS,()->statusLabel.getText().equals("Message sent successfully."));
String status = statusLabel.getText();
assertEquals("Message sent successfully.",status);
}
}