Skip to content

Commit

Permalink
Merge pull request #9 from telekom/refactoring/test-name-cap-only-whe…
Browse files Browse the repository at this point in the history
…n-absent

Refactoring/test name cap only when absent
  • Loading branch information
Mike Reiche authored and martingrossmann committed Dec 15, 2022
2 parents 415d40e + 9405b63 commit 1f52810
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/.

# These are the default owners for the whole content of this repository. The default owners are automatically added as reviewers when you open a pull request, unless different owners are specified in the file.
* @mreiche @martingrossmann @gogro
* @mreiche @martingrossmann @gogro @mbeuthan
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
import io.appium.java_client.remote.MobileBrowserType;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
Expand All @@ -50,6 +52,7 @@
*/
public class AppiumDriverFactory extends WebDriverFactory<AppiumDriverRequest> {


@Override
protected AppiumDriverRequest buildRequest(AbstractWebDriverRequest webDriverRequest) {

Expand All @@ -72,8 +75,23 @@ protected AppiumDriverRequest buildRequest(AbstractWebDriverRequest webDriverReq

@Override
protected DesiredCapabilities buildCapabilities(DesiredCapabilities preSetCaps, AppiumDriverRequest request) {
return request.getDesiredCapabilities().merge(preSetCaps);
}

return preSetCaps;
/**
* Sets an capability value if the existing value doesn't match the same type,
* is an empty string or doesn't exists.
* @todo Move this to Testerra core
* @param capabilities
* @param capabilityName
* @param capability
* @param <T>
*/
private <T> void setCapabilityIfAbsent(DesiredCapabilities capabilities, String capabilityName, T capability) {
Object existingCapability = capabilities.getCapability(capabilityName);
if (!capability.getClass().isInstance(existingCapability) || (existingCapability instanceof String && StringUtils.isBlank((String)existingCapability))) {
capabilities.setCapability(capabilityName, capability);
}
}

@Override
Expand All @@ -90,7 +108,7 @@ protected WebDriver getRawWebDriver(AppiumDriverRequest webDriverRequest, Desire
}

// general caps
desiredCapabilities.setCapability("testName", ExecutionContextController.getCurrentExecutionContext().runConfig.getReportName());
setCapabilityIfAbsent(desiredCapabilities, AppiumDriverRequest.CAPABILITY_NAME_TEST_NAME, ExecutionContextController.getCurrentExecutionContext().runConfig.getReportName());
desiredCapabilities.setCapability("accessKey", GRID_ACCESS_KEY);

switch (webDriverRequest.getBrowser()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*/
public class AppiumDriverRequest extends AbstractWebDriverRequest {

public static final String CAPABILITY_NAME_TEST_NAME = "testName";

private AppiumDeviceQuery appiumDeviceQuery;

public AppiumDeviceQuery getAppiumDeviceQuery() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@
package eu.tsystems.mms.tic.testframework.mobile.test.driver;

import eu.tsystems.mms.tic.testframework.internal.Viewport;
import eu.tsystems.mms.tic.testframework.mobile.driver.AppiumDriverRequest;
import eu.tsystems.mms.tic.testframework.mobile.test.AbstractAppiumTest;
import eu.tsystems.mms.tic.testframework.report.model.context.Screenshot;
import eu.tsystems.mms.tic.testframework.report.model.context.SessionContext;
import eu.tsystems.mms.tic.testframework.utils.JSUtils;
import eu.tsystems.mms.tic.testframework.utils.UITestUtils;
import eu.tsystems.mms.tic.testframework.webdrivermanager.WebDriverManager;
import eu.tsystems.mms.tic.testframework.webdrivermanager.WebDriverSessionsManager;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import java.util.Map;
import org.openqa.selenium.ScreenOrientation;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
Expand All @@ -46,11 +50,18 @@ public class TesterraAppiumDriverTest extends AbstractAppiumTest {
@Test
public void testT01_startDefaultSession() {

final WebDriver driver = WebDriverManager.getWebDriver();
final AppiumDriver<MobileElement> appiumDriver = appiumDriverManager.fromWebDriver(driver);
String expectedTestName = "testT01_startDefaultSession";

AppiumDriverRequest appiumDriverRequest = new AppiumDriverRequest();
appiumDriverRequest.getDesiredCapabilities().setCapability(AppiumDriverRequest.CAPABILITY_NAME_TEST_NAME, expectedTestName);

WebDriver webDriver = WebDriverManager.getWebDriver(appiumDriverRequest);
AppiumDriver<MobileElement> appiumDriver = appiumDriverManager.fromWebDriver(webDriver);

appiumDriver.rotate(ScreenOrientation.LANDSCAPE);
driver.get("https://the-internet.herokuapp.com/dropdown");
webDriver.get("https://the-internet.herokuapp.com/dropdown");

Assert.assertEquals(appiumDriver.getCapabilities().getCapability(AppiumDriverRequest.CAPABILITY_NAME_TEST_NAME), expectedTestName);
}

@Test
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ ext {
}

allprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'java-library'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down

0 comments on commit 1f52810

Please sign in to comment.