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

Allow users to override CodingManager to customize the abstraction #276

Merged
merged 4 commits into from
Jul 1, 2021
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
28 changes: 28 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,77 +20,99 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Prepare TESTAR protocols
run: ./gradlew init_workflow_test

- name: Build TESTAR with Gradle
run: ./gradlew build

- name: Prepare installed distribution of TESTAR with Gradle
run: ./gradlew installDist

- name: Run desktop_generic protocol with TESTAR using COMMAND_LINE
run: ./gradlew runTestDesktopGenericCommandLineOk
- name: Save runTestDesktopGenericCommandLineOk HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestDesktopGenericCommandLineOk-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/notepad_ok

- name: Run desktop_generic protocol that contains SuspiciousTitle with TESTAR
run: ./gradlew runTestDesktopGenericCommandLineSuspiciousTitle
- name: Save runTestDesktopGenericCommandLineSuspiciousTitle HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestDesktopGenericCommandLineSuspiciousTitle-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/notepad_command_and_suspicious

- name: Run desktop_generic protocol using specific filtering and detect a SuspiciousTitle with TESTAR
run: ./gradlew runTestDesktopGenericCommandLineSettingsFilterSuspiciousTitle
- name: Save runTestDesktopGenericCommandLineSettingsFilterSuspiciousTitle HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestDesktopGenericCommandLineSettingsFilterSuspiciousTitle-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/notepad_command_settings_filter_and_suspicious

- name: Run desktop_generic protocol but connect using SUT_PROCESS_NAME and detect SuspiciousTitle
run: ./gradlew runTestDesktopGenericProcessNameSuspiciousTitle
- name: Save runTestDesktopGenericProcessNameSuspiciousTitle HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestDesktopGenericProcessNameSuspiciousTitle-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/notepad_process_and_suspicious

- name: Run desktop_generic protocol but connect using SUT_WINDOW_TITLE and detect SuspiciousTitle
run: ./gradlew runTestDesktopGenericTitleNameSuspiciousTitle
- name: Save runTestDesktopGenericTitleNameSuspiciousTitle HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestDesktopGenericTitleNameSuspiciousTitle-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/notepad_title_and_suspicious

- name: Run desktop_generic with OrientDB to infer a TESTAR State Model
run: ./gradlew runTestDesktopGenericStateModel
- name: Save runTestDesktopGenericStateModel HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestDesktopGenericStateModel-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/notepad_state_model

- name: Run desktop_generic doing a customization in the AbstractIDCustom identifer
run: ./gradlew runTestDesktopGenericStateModelCustomAbstraction
- name: Save runTestDesktopGenericStateModelCustomAbstraction HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestDesktopGenericStateModelCustomAbstraction-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/notepad_state_model_custom

- name: Run webdriver protocol and detect SuspiciousTitle
run: ./gradlew runTestWebdriverSuspiciousTitle
- name: Save runTestWebdriverSuspiciousTitle HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestWebdriverSuspiciousTitle-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/webdriver_and_suspicious

- name: Run webdriver to login in parabank app
run: ./gradlew runTestWebdriverParabankLogin
- name: Save runTestWebdriverParabankLogin HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestWebdriverParabankLogin-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/webdriver_login

- name: Run TESTAR Replay mode with a web page to check that replayed correctly
run: ./gradlew runTestWebdriverCorrectReplay
- name: Save runTestWebdriverCorrectReplay HTML report artifact
uses: actions/upload-artifact@v2
with:
name: runTestWebdriverCorrectReplay-artifact
path: D:/a/TESTAR_dev/TESTAR_dev/testar/target/install/testar/bin/webdriver_replay

- name: Run TESTAR Replay mode to detect a not replayable button
run: ./gradlew runTestWebdriverUnreplayable
- name: Save runTestWebdriverUnreplayable HTML report artifact
Expand All @@ -109,10 +131,13 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build TESTAR with Gradle
run: ./gradlew build

- name: Prepare installed distribution of TESTAR with Gradle
run: ./gradlew installDist

Expand All @@ -126,9 +151,12 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build TESTAR with Gradle
run: ./gradlew build

- name: Prepare installed distribution of TESTAR with Gradle
run: ./gradlew installDist
27 changes: 9 additions & 18 deletions core/src/es/upv/staq/testar/CodingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ public static synchronized void buildIDs(Widget widget){
* @param actions The actions.
*/
public static synchronized void buildIDs(State state, Set<Action> actions){
for (Action a : actions)
CodingManager.buildIDs(state,a);
for (Action a : actions) {
a.set(Tags.ConcreteID, ID_PREFIX_ACTION + ID_PREFIX_CONCRETE +
CodingManager.codify(state.get(Tags.ConcreteID), a));
a.set(Tags.ConcreteIDCustom, ID_PREFIX_ACTION + ID_PREFIX_CONCRETE_CUSTOM +
CodingManager.codify(state.get(Tags.ConcreteIDCustom), a));
a.set(Tags.AbstractID, ID_PREFIX_ACTION + ID_PREFIX_ABSTRACT +
CodingManager.codify(state.get(Tags.ConcreteID), a, ROLES_ABSTRACT_ACTION));
}

// for the custom abstract action identifier, we first sort the actions by their path in the widget tree
// and then set their ids using incremental counters
Expand All @@ -213,22 +219,7 @@ public static synchronized void buildIDs(State state, Set<Action> actions){
}
);
}

/**
* Builds IDs (abstract, concrete, precise) for an action.
* @param action An action.
*/
public static synchronized void buildIDs(State state, Action action){
action.set(Tags.ConcreteID, ID_PREFIX_ACTION + ID_PREFIX_CONCRETE +
CodingManager.codify(state.get(Tags.ConcreteID), action));
action.set(Tags.ConcreteIDCustom, ID_PREFIX_ACTION + ID_PREFIX_CONCRETE_CUSTOM +
CodingManager.codify(state.get(Tags.ConcreteIDCustom), action));
action.set(Tags.AbstractID, ID_PREFIX_ACTION + ID_PREFIX_ABSTRACT +
CodingManager.codify(state.get(Tags.ConcreteID), action, ROLES_ABSTRACT_ACTION));
// action.set(Tags.AbstractIDCustom, ID_PREFIX_ACTION + ID_PREFIX_ABSTRACT_CUSTOM +
// CodingManager.codify(state.get(Tags.AbstractIDCustom), action, ROLES_ABSTRACT_ACTION));
}


/**
* Builds IDs (abstract, concrete, precise) for an environment action.
* @param action An action.
Expand Down
46 changes: 37 additions & 9 deletions testar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ task verifyOrientDB(type: Verify, dependsOn: downloadOrientDB) {
algorithm 'MD5'
checksum 'a0619e5522e7d849d4f1067bf08e3857'
}
// Extract LabRecruits binary files
// Extract OrientDB binary files
task downloadAndUnzipOrientDB(type: Copy, dependsOn: verifyOrientDB) {
group = 'test_testar_workflow'
description ='downloadAndUnzipOrientDB'
Expand All @@ -364,13 +364,20 @@ task createDatabaseOrientDB(type: Exec, dependsOn: downloadAndUnzipOrientDB){
}
// Read command line output
standardOutput = new ByteArrayOutputStream()
errorOutput = new ByteArrayOutputStream()
workingDir 'target/install/testar/bin/orientdb-3.0.34/bin'
commandLine 'cmd', '/c', 'console.bat CREATE DATABASE plocal:../databases/testar admin admin'
// Ignore errors creating the database because we check the output buffer message
ignoreExitValue true
doLast {
String output = standardOutput.toString()

// Check if testar database created sucessfully
if(output.readLines().any{line->line.contains("Database created successfully.")}) {

// If error creating database because already exists is ok
if (execResult.getExitValue()==1 && errorOutput.toString().contains("Cannot create new database 'testar' because it already exists")) {
println "\n${output} \ntestar OrientDB database already exists"
}
// Check if testar database created sucessfully
else if(output.readLines().any{line->line.contains("Database created successfully.")}) {
println "\n${output} \ntestar OrientDB database created successfully"
} else {
throw new GradleException("\n${output} \nERROR: Creating testar OrientDB database")
Expand All @@ -389,7 +396,7 @@ task runTestDesktopGenericStateModel(type: Exec, dependsOn: createDatabaseOrient
doLast {
String output = standardOutput.toString()

// Check that output contains 3 abstract states in the State Model inference
// Check that output contains 3 abstract states in the State Model inference
if(output.readLines().any{line->line.contains("3 abstract states in the model")}) {
println "\n${output} \nTESTAR State Model has been inferred sucessfully"
} else {
Expand All @@ -398,6 +405,27 @@ task runTestDesktopGenericStateModel(type: Exec, dependsOn: createDatabaseOrient
}
}

// Verify that TESTAR can custom the widget and actions identifiers
// Infer a State Model modifying the state and action identifiers
task runTestDesktopGenericStateModelCustomAbstraction(type: Exec, dependsOn: createDatabaseOrientDB) {
// Read command line output
standardOutput = new ByteArrayOutputStream()
group = 'test_testar_workflow'
description ='runTestDesktopGenericStateModelCustomAbstraction'
workingDir 'target/install/testar/bin'
commandLine 'cmd', '/c', 'testar sse=test_gradle_workflow_desktop_generic_custom_abstraction AlwaysCompile=true ApplicationName="notepad_state_model_custom" ShowVisualSettingsDialogOnStartup=false Mode=Generate SUTConnector=COMMAND_LINE SUTConnectorValue="C:\\\\Windows\\\\System32\\\\notepad.exe" Sequences=1 SequenceLength=1'
doLast {
String output = standardOutput.toString()

// Check that output contains 0 unvisited actions left
if(output.contains("0 unvisited actions left")) {
println "\n${output} \nTESTAR Action AbstractIDCustom has been customized sucessfully"
} else {
throw new GradleException("\n${output} \nERROR: with Action AbstractIDCustom custom identifier")
}
}
}

// Download last win32 chromedriver
task downloadChromedriver(type: Download, dependsOn: installDist) {
group = 'test_testar_workflow'
Expand Down Expand Up @@ -474,7 +502,7 @@ task runTestWebdriverParabankLogin(type: Exec, dependsOn: downloadAndUnzipChrome

// Verify that TESTAR correctly replays a sequence
task runTestWebdriverCorrectReplay(type: Exec, dependsOn: downloadAndUnzipChromedriver) {
// Read command line output
// Read command line output
standardOutput = new ByteArrayOutputStream()
group = 'test_testar_workflow'
description ='runTestWebdriverCorrectReplay'
Expand All @@ -483,7 +511,7 @@ task runTestWebdriverCorrectReplay(type: Exec, dependsOn: downloadAndUnzipChrome
doLast {
String output = standardOutput.toString()

// Check that output contains Sequence successfully replayed message to verify the correct replay execution
// Check that output contains Sequence successfully replayed message to verify the correct replay execution
if(output.readLines().any{line->line.contains("Sequence successfully replayed")}) {
println "\n${output} \nTESTAR sequence has been sucessfully replayed"
} else {
Expand All @@ -494,7 +522,7 @@ task runTestWebdriverCorrectReplay(type: Exec, dependsOn: downloadAndUnzipChrome

// Verify that TESTAR correctly detects a not replayable sequence
task runTestWebdriverUnreplayable(type: Exec, dependsOn: downloadAndUnzipChromedriver) {
// Read command line output
// Read command line output
standardOutput = new ByteArrayOutputStream()
group = 'test_testar_workflow'
description ='runTestWebdriverUnreplayable'
Expand All @@ -503,7 +531,7 @@ task runTestWebdriverUnreplayable(type: Exec, dependsOn: downloadAndUnzipChromed
doLast {
String output = standardOutput.toString()

// Check that TESTAR detects not replayable button
// Check that TESTAR detects not replayable button
if(output.readLines().any{line->line.contains("Left Click at 'ParisThree' of the replayed sequence can not been replayed")}) {
println "\n${output} \nTESTAR has sucessfully detected a not replayable sequence"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.fruit.monkey.RuntimeControlsProtocol.Modes;
import org.testar.protocols.DesktopProtocol;

import es.upv.staq.testar.CodingManager;

/**
* This protocol combines different functionalities of TESTAR for testing Windows desktop applications
* into one protocol.
Expand Down Expand Up @@ -260,4 +262,47 @@ protected void stopSystem(SUT system) {
protected void postSequenceProcessing() {
super.postSequenceProcessing();
}

/**
* This method allow users to customize the Widget and State identifiers.
*
* By default TESTAR uses the CodingManager to create the Widget and State identifiers:
* ConcreteID, ConcreteIDCustom, AbstractID, AbstractIDCustom,
* Abstract_R_ID, Abstract_R_T_ID, Abstract_R_T_P_ID
*
* @param state
*/
@Override
protected void buildStateIdentifiers(State state) {
CodingManager.buildIDs(state);
}

/**
* This method allow users to customize the Actions identifiers.
*
* By default TESTAR uses the CodingManager to create the Actions identifiers:
* ConcreteID, ConcreteIDCustom, AbstractID, AbstractIDCustom
*
* @param state
* @param actions
*/
@Override
protected void buildStateActionsIdentifiers(State state, Set<Action> actions) {
CodingManager.buildIDs(state, actions);
}

/**
* This method allow users to customize the environment Action identifiers.
* These are Actions not related to a Widget (ForceToForeground, Keyboard, KillProcess, etc...)
*
* By default TESTAR uses the CodingManager to create the specific environment Action identifiers:
* ConcreteID, ConcreteIDCustom, AbstractID, AbstractIDCustom
*
* @param state
* @param action
*/
@Override
protected void buildEnvironmentActionIdentifiers(State state, Action action) {
CodingManager.buildEnvironmentActionIDs(state, action);
}
}
Loading