Skip to content

Commit

Permalink
Add Recording feature and convert to corresponding curl commands (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
agoelzer authored Jan 7, 2025
1 parent 6349e55 commit de37360
Show file tree
Hide file tree
Showing 24 changed files with 625 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,36 @@ public void sleep(int ms) {
Thread.currentThread().interrupt();
}
}

public void retry(Runnable r) {
retry(10, 100, r);
}

public void retry(int count, long delayMS, Runnable r) {
Throwable exception = null;
for(int i=count; i>=0; i--) {
try {
r.run();
return;
}
catch(Throwable e) {
exception = e;
}
try {
Thread.sleep(delayMS);
}
catch(InterruptedException e) {
Thread.currentThread().interrupt();
}
}
throw new RuntimeException(exception);
}

public void clearSessionStorage(String key) {
((JavascriptExecutor)driver).executeScript("window.sessionStorage.removeItem(\"" + key + "\")");
}

public String getSessionStorage(String key) {
return (String) ((JavascriptExecutor)driver).executeScript("return window.sessionStorage.getItem(\"" + key + "\")");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public void clickPopupMenu(WebElement element, String dataTestId) {
menuItems.get(0).click();
}

public void clickUserMenu(String dataTestId) {
WebElement userMenu = waitElement("user-menu");
clickPopupMenu(userMenu, dataTestId);
}

private void createResource(Resource resource, String name, String ...fieldValueList) {
clickMenu(resource.name());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// (C) Copyright 2024 Dassault Systemes SE. All Rights Reserved.

package com.nuodb.selenium.basic;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nuodb.selenium.Constants;
import com.nuodb.selenium.TestRoutines;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AutomationTest extends TestRoutines {
@Test
public void testRecordingCreateAndDeleteUsers() throws JsonProcessingException {
// Start Recording
login(Constants.ADMIN_ORGANIZATION, Constants.ADMIN_USER, Constants.ADMIN_PASSWORD);
clickUserMenu("automation");
clearSessionStorage("nuodbaas-webui-recorded");
clearSessionStorage("nuodbaas-webui-isRecording");
click("btnStartRecording");

// Setup and list users
String userName = createUser();
clickMenu("users");

// find user and delete
deleteUser(userName);
waitRestComplete();

// Stop Recording
retry(()->{
clickUserMenu("automation");
click("btnStopRecording");
});

// Validate recording
String strRecording = getSessionStorage("nuodbaas-webui-recorded");
ObjectMapper mapper = new ObjectMapper();
JsonNode items = mapper.readTree(strRecording);
int [] putDelete = { 0, 0};
items.forEach(item -> {
String method = item.get("method").asText();
if(method.equalsIgnoreCase("put")) {
putDelete[0]++;
}
else if(method.equalsIgnoreCase("delete")) {
putDelete[1]++;
}
});
assertEquals(1, putDelete[0]);
assertEquals(1, putDelete[1]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public void testListCreateAndDeleteBackups() {

// verify backup is gone
waitRestComplete();
List<WebElement> buttonsCell = waitTableElements("list_resource__table", "name", backupName, MENU_COLUMN);
assertEquals(0, buttonsCell.size());
retry(()->{
List<WebElement> buttonsCell = waitTableElements("list_resource__table", "name", backupName, MENU_COLUMN);
assertEquals(0, buttonsCell.size());
});
}

@Test
Expand All @@ -68,10 +70,12 @@ public void testEditBackup() {
waitRestComplete();

// verify backup was modified
List<WebElement> labelCells = waitTableElements("list_resource__table", "name", backupName, "labels");
assertThat(labelCells)
.hasSize(1)
.get(0)
.mapContains(projectName, databaseName);
retry(()->{
List<WebElement> labelCells = waitTableElements("list_resource__table", "name", backupName, "labels");
assertThat(labelCells)
.hasSize(1)
.get(0)
.mapContains(projectName, databaseName);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public void testListCreateAndDeleteDatabases() {

// verify database is gone
waitRestComplete();
List<WebElement> buttonsCell = waitTableElements("list_resource__table", "name", databaseName, MENU_COLUMN);
assertEquals(0, buttonsCell.size());
retry(()->{
List<WebElement> buttonsCell = waitTableElements("list_resource__table", "name", databaseName, MENU_COLUMN);
assertEquals(0, buttonsCell.size());
});
}

@Test
Expand All @@ -64,11 +66,13 @@ public void testEditDatabase() {
waitRestComplete();

// verify database was modified
List<WebElement> labelCells = waitTableElements("list_resource__table", "name", databaseName, "labels");
assertThat(labelCells)
.hasSize(1)
.get(0)
.mapContains(projectName, databaseName);
retry(()->{
List<WebElement> labelCells = waitTableElements("list_resource__table", "name", databaseName, "labels");
assertThat(labelCells)
.hasSize(1)
.get(0)
.mapContains(projectName, databaseName);
});
}

private WebElement findSingleDatabaseButton(String databaseName, String buttonLabel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public void testListCreateAndDeleteProjects() {

// verify project is gone
waitRestComplete();
List<WebElement> buttonsCell = waitTableElements("list_resource__table", "name", projectName, MENU_COLUMN);
assertEquals(0, buttonsCell.size());
retry(()->{
List<WebElement> buttonsCell = waitTableElements("list_resource__table", "name", projectName, MENU_COLUMN);
assertEquals(0, buttonsCell.size());
});

}

Expand All @@ -61,11 +63,13 @@ public void testEditProject() {
waitRestComplete();

// verify project was modified
List<WebElement> tierCells = waitTableElements("list_resource__table", "name", projectName, "tier");
assertThat(tierCells)
.hasSize(1)
.get(0)
.hasValue("n0.small");
retry(()->{
List<WebElement> tierCells = waitTableElements("list_resource__table", "name", projectName, "tier");
assertThat(tierCells)
.hasSize(1)
.get(0)
.hasValue("n0.small");
});

List<WebElement> maintenanceCells = waitTableElements("list_resource__table", "name", projectName, "maintenance");
assertThat(maintenanceCells)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,72 @@ public void testSearch() throws IOException {
login(Constants.ADMIN_ORGANIZATION, Constants.ADMIN_USER, Constants.ADMIN_PASSWORD);
clickMenu("users");
waitRestComplete();
List<WebElement> nameCell = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(20, nameCell.size());
retry(()->{
List<WebElement> nameCell = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(20, nameCell.size());
});

// search users starting with "1" index and check that 10 users are returned
replaceInputElementByName("search", name + "1");
waitElement("searchButton").click();
waitRestComplete();
nameCell = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(10, nameCell.size());
retry(()-> {
var nc = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(10, nc.size());
});

// search users by label existence
replaceInputElementByName("search", "label=label1");
waitElement("searchButton").click();
waitRestComplete();
nameCell = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(20, nameCell.size());
retry(()-> {
var nc = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(20, nc.size());
});

// search users by label value
replaceInputElementByName("search", "label=label2=" + name + "8");
waitElement("searchButton").click();
waitRestComplete();
nameCell = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(9, nameCell.size());
retry(()->{
var nc = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(9, nc.size());
});

// search users by label value and name
replaceInputElementByName("search", "label=label2=" + name + "8" + " name=" + name + "1");
waitElement("searchButton").click();
waitRestComplete();
nameCell = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(1, nameCell.size());
retry(()-> {
var nc = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(1, nc.size());
});

// search users by partial name
replaceInputElementByName("search", "name=" + name + "1");
waitElement("searchButton").click();
waitRestComplete();
nameCell = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(10, nameCell.size());
retry(()->{
var nc = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(10, nc.size());
});

// search users by full name
replaceInputElementByName("search", "name=" + name + "19");
waitElement("searchButton").click();
waitRestComplete();
nameCell = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(1, nameCell.size());
retry(()->{
var nc = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(1, nc.size());
});

// search users by invalid name
replaceInputElementByName("search", "name=" + name + "invalid");
waitElement("searchButton").click();
waitRestComplete();
nameCell = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(0, nameCell.size());
retry(()->{
var nc = waitTableElements("list_resource__table", "name", null, "name");
assertEquals(0, nc.size());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package com.nuodb.selenium.basic;

import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.nuodb.selenium.Constants;
Expand Down Expand Up @@ -36,8 +35,10 @@ public void testListCreateAndDeleteUsers() {

// verify user is gone
waitRestComplete();
List<WebElement> buttonsCell = waitTableElements("list_resource__table", "name", userName, MENU_COLUMN);
assertEquals(0, buttonsCell.size());
retry(()-> {
List<WebElement> buttonsCell = waitTableElements("list_resource__table", "name", userName, MENU_COLUMN);
assertEquals(0, buttonsCell.size());
});
}

@Test
Expand Down Expand Up @@ -69,10 +70,12 @@ public void testEditUser() {
waitRestComplete();

// verify user was modified
List<WebElement> labelsCells = waitTableElements("list_resource__table", "name", userName, "labels");
assertThat(labelsCells)
.hasSize(1)
.get(0)
.mapContains(userName, userName);
retry(()->{
List<WebElement> labelsCells = waitTableElements("list_resource__table", "name", userName, "labels");
assertThat(labelsCells)
.hasSize(1)
.get(0)
.mapContains(userName, userName);
});
}
}
16 changes: 16 additions & 0 deletions ui/public/theme/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
margin-left: auto;
margin-right: auto;
}
.NuoContainerLG {
max-width: 100%;
margin-left: 24px;
margin-right: 24px;
}
.NuoBanner {
width: 100%;
padding-left: 24px;
Expand Down Expand Up @@ -317,3 +322,14 @@ code {
height: 25px;
float: left;
}

.NuoButtons {
display: flex;
flex-direction: row;
gap: 10px;
margin: 5px 0;
}
.NuoRecordingBanner {
background-color: #e0e033;
padding: 5px 24px;
}
Loading

0 comments on commit de37360

Please sign in to comment.