Skip to content

Commit

Permalink
Merge pull request #35 from aquality-automation/breaking/add-visualiz…
Browse files Browse the repository at this point in the history
…ation

[Feature][Breaking] Visualization
  • Loading branch information
aqualityAutomation authored Mar 15, 2023
2 parents 23edfa3 + d77141e commit 8668269
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ We use interfaces where is possible, so you can implement your own version of ta

### Quick start

To start the project using Aquality.Selenium framework, you can [download our template BDD project by this link.](https://github.com/aquality-automation/aquality-appium-mobile-java-template)
To start the project using aquality.appium.mobile framework, you can [download our template BDD project by this link.](https://github.com/aquality-automation/aquality-appium-mobile-java-template)

Alternatively, you can follow the steps below:

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-appium-mobile</artifactId>
<version>3.1.2</version>
<version>4.0.0</version>

<packaging>jar</packaging>
<name>Aquality Appium Mobile</name>
Expand Down Expand Up @@ -172,7 +172,7 @@
<dependency>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium-core</artifactId>
<version>2.0.5</version>
<version>3.0.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package aquality.appium.mobile.configuration;

import aquality.selenium.core.configurations.IElementCacheConfiguration;
import aquality.selenium.core.configurations.ILoggerConfiguration;
import aquality.selenium.core.configurations.IRetryConfiguration;
import aquality.selenium.core.configurations.ITimeoutConfiguration;
import aquality.selenium.core.configurations.*;
import com.google.inject.Inject;

public class Configuration implements IConfiguration {
Expand All @@ -14,18 +11,20 @@ public class Configuration implements IConfiguration {
private final ILoggerConfiguration loggerConfiguration;
private final IElementCacheConfiguration elementCacheConfiguration;
private final ITouchActionsConfiguration touchActionsConfiguration;
private final IVisualizationConfiguration visualizationConfiguration;

@Inject
public Configuration(ITimeoutConfiguration timeoutConfiguration, IRetryConfiguration retryConfiguration,
IApplicationProfile applicationProfile, ILoggerConfiguration loggerConfiguration,
IElementCacheConfiguration elementCacheConfiguration,
ITouchActionsConfiguration touchActionsConfiguration) {
ITouchActionsConfiguration touchActionsConfiguration, IVisualizationConfiguration visualizationConfiguration) {
this.timeoutConfiguration = timeoutConfiguration;
this.retryConfiguration = retryConfiguration;
this.applicationProfile = applicationProfile;
this.loggerConfiguration = loggerConfiguration;
this.elementCacheConfiguration = elementCacheConfiguration;
this.touchActionsConfiguration = touchActionsConfiguration;
this.visualizationConfiguration = visualizationConfiguration;
}

@Override
Expand Down Expand Up @@ -57,4 +56,9 @@ public IElementCacheConfiguration getElementCacheConfiguration() {
public ITouchActionsConfiguration getTouchActionsConfiguration() {
return touchActionsConfiguration;
}

@Override
public IVisualizationConfiguration getVisualizationConfiguration() {
return visualizationConfiguration;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package aquality.appium.mobile.configuration;

import aquality.selenium.core.configurations.IElementCacheConfiguration;
import aquality.selenium.core.configurations.ILoggerConfiguration;
import aquality.selenium.core.configurations.IRetryConfiguration;
import aquality.selenium.core.configurations.ITimeoutConfiguration;
import aquality.selenium.core.configurations.*;

/**
* Describes tools configuration.
*/
public interface IConfiguration {

/**
Expand Down Expand Up @@ -48,4 +48,11 @@ public interface IConfiguration {
* @return Configuration of touch actions.
*/
ITouchActionsConfiguration getTouchActionsConfiguration();

/**
* Gets configuration of VisualStateProvider and Dump manager.
*
* @return Visualization configuration.
*/
IVisualizationConfiguration getVisualizationConfiguration();
}
6 changes: 6 additions & 0 deletions src/main/java/aquality/appium/mobile/elements/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import aquality.selenium.core.localization.ILocalizationManager;
import aquality.selenium.core.localization.ILocalizedLogger;
import aquality.selenium.core.utilities.IElementActionRetrier;
import aquality.selenium.core.visualization.IImageComparator;
import aquality.selenium.core.waitings.IConditionalWait;
import org.openqa.selenium.*;

Expand Down Expand Up @@ -45,6 +46,11 @@ protected IElementFinder getElementFinder() {
return AqualityServices.get(IElementFinder.class);
}

@Override
protected IImageComparator getImageComparator() {
return AqualityServices.get(IImageComparator.class);
}

@Override
protected IElementCacheConfiguration getElementCacheConfiguration() {
return AqualityServices.get(IElementCacheConfiguration.class);
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/aquality/appium/mobile/screens/IScreen.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package aquality.appium.mobile.screens;

import aquality.selenium.core.elements.interfaces.IElementStateProvider;
import aquality.selenium.core.forms.IForm;
import aquality.selenium.core.visualization.IDumpManager;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;

public interface IScreen {
import java.awt.*;

/**
* Defines interface for any UI form.
*/
public interface IScreen extends IForm {
/**
* Locator for specified screen
*/
Expand All @@ -26,4 +32,13 @@ public interface IScreen {
* @return provider to define element's state
*/
IElementStateProvider state();


/**
* Gets dump manager for the current form that could be used for visualization purposes,
* such as saving and comparing dumps.
*
* @return form's dump manager.
*/
IDumpManager dump();
}
54 changes: 47 additions & 7 deletions src/main/java/aquality/appium/mobile/screens/Screen.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,84 @@
package aquality.appium.mobile.screens;

import aquality.appium.mobile.application.AqualityServices;
import aquality.appium.mobile.elements.interfaces.IElement;
import aquality.appium.mobile.elements.interfaces.IElementFactory;
import aquality.appium.mobile.elements.interfaces.ILabel;
import aquality.selenium.core.configurations.IVisualizationConfiguration;
import aquality.selenium.core.elements.interfaces.IElementStateProvider;
import aquality.selenium.core.forms.Form;
import aquality.selenium.core.localization.ILocalizedLogger;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;

public abstract class Screen implements IScreen {
import java.awt.*;

/**
* Defines base class for any UI form.
*/
public abstract class Screen extends Form<IElement> implements IScreen {
/**
* Locator for specified form
*/
private final By locator;
/**
* Name of specified form
*/
private final String name;
private final ILabel screenLabel;
/**
* Screen element defined by its locator and name.
*/
private final IElement screenElement;

/**
* Constructor with parameters
*/
protected Screen(By locator, String name) {
super(IElement.class);
this.locator = locator;
this.name = name;
this.screenLabel = getElementFactory().getLabel(locator, name);
this.screenElement = getElementFactory().getLabel(locator, name);
}

@Override
public By getLocator() {
return locator;
}

@Override
public String getName() {
return name;
}

@Override
public Dimension getSize() {
return screenLabel.getElement().getSize();
return screenElement.visual().getSize();
}

@Override
public IElementStateProvider state() {
return screenLabel.state();
return screenElement.state();
}

/**
* Gets form element defined by its locator and name.
* Could be used to find child elements relative to form element.
*
* @return form element.
*/
protected IElement getScreenElement() {
return screenElement;
}

protected IElementFactory getElementFactory(){
return AqualityServices.getElementFactory();
}

@Override
protected IVisualizationConfiguration getVisualizationConfiguration() {
return AqualityServices.getConfiguration().getVisualizationConfiguration();
}

@Override
protected ILocalizedLogger getLocalizedLogger() {
return AqualityServices.getLocalizedLogger();
}
}
8 changes: 8 additions & 0 deletions src/main/resources/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,13 @@
"verticalOffset": 0.2,
"horizontalOffset": 0.5
}
},
"visualization": {
"imageExtension": "png",
"maxFullFileNameLength": 255,
"defaultThreshold": 0.012,
"comparisonWidth": 16,
"comparisonHeight": 16,
"pathToDumps": "./src/test/resources/visualDumps/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ public void testSendKeys() {
Assert.assertEquals(searchScreen.getSearchResult(), query, "Search result don't match to entered query");
}

@Test
public void testSaveAndCompareScreenDump()
{
InvokeSearchScreen searchScreen = ApplicationActivity.SEARCH.open();
Assert.assertTrue(searchScreen.state().isDisplayed(), String.format("%s should be opened", searchScreen.getName()));
final String customDumpName = String.format("my dump of %s", searchScreen.getName());
searchScreen.dump().save(customDumpName);
Assert.assertEquals(searchScreen.dump().compare(customDumpName), 0, "Current screen should have no visual difference comparing to just saved dump");
final String query = "Hello world!";
searchScreen.typeQuery(query);
Assert.assertTrue(searchScreen.dump().compare() > 0, "Current screen after the search should have visual difference comparing to dump saved");
}

@Test
public void testRadioButton() {
ITestRadioButton.super.testRadioButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ protected AndroidScreen(By locator, String name) {
super(locator, name);
}

@SuppressWarnings("unchecked")
protected void startActivity(Activity activity) {
AqualityServices.getLocalizedLogger().info("loc.application.android.activity.start",
activity.getAppActivity(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ public InvokeSearchScreen() {
}

public void submitSearch(String query) {
txbSearch.clearAndType(query);
typeQuery(query);
btnStartSearch.click();
}

public void typeQuery(String query) {
txbSearch.clearAndType(query);
}

public String getSearchResult() {
return lblSearchResult.getText();
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,13 @@
"verticalOffset": 0.2,
"horizontalOffset": 0.5
}
},
"visualization": {
"imageExtension": "png",
"maxFullFileNameLength": 255,
"defaultThreshold": 0.012,
"comparisonWidth": 16,
"comparisonHeight": 16,
"pathToDumps": "./src/test/resources/visualDumps/"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8668269

Please sign in to comment.