Skip to content

Commit

Permalink
Merge branch 'master' into 3642
Browse files Browse the repository at this point in the history
  • Loading branch information
EDbarvinsky authored Mar 17, 2023
2 parents 779f550 + b9b913e commit 8065ea3
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,8 +53,7 @@ protected AbstractVividusWebDriverFactory(boolean remoteExecution, WebDriverStar
public VividusWebDriver create()
{
VividusWebDriver vividusWebDriver = new VividusWebDriver();
vividusWebDriver.setDesiredCapabilities(getDesiredCapabilities());
vividusWebDriver.setWebDriver(createWebDriver(vividusWebDriver.getDesiredCapabilities()));
vividusWebDriver.setWebDriver(createWebDriver(getDesiredCapabilities()));
vividusWebDriver.setRemote(remoteExecution);
return vividusWebDriver;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,24 +18,12 @@

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WrapsDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class VividusWebDriver implements WrapsDriver
{
private DesiredCapabilities desiredCapabilities;
private WebDriver webDriver;
private boolean remote;

public DesiredCapabilities getDesiredCapabilities()
{
return desiredCapabilities;
}

public void setDesiredCapabilities(DesiredCapabilities desiredCapabilities)
{
this.desiredCapabilities = desiredCapabilities;
}

public void setWebDriver(WebDriver webDriver)
{
this.webDriver = webDriver;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -147,6 +147,12 @@ public static boolean isAndroid(Capabilities capabilities)
return isPlatformName(capabilities, MobilePlatform.ANDROID);
}

@Override
public boolean isMacOs()
{
return isPlatformName(getCapabilities(), "MacOS");
}

private static boolean isPlatformName(Capabilities capabilities, String platformName)
{
return checkCapabilities(capabilities, () ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,5 +38,7 @@ public interface IGenericWebDriverManager

boolean isAndroid();

boolean isMacOs();

Capabilities getCapabilities();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -125,7 +125,7 @@ void shouldCreateWebDriverWithCapabilitiesFromConfigurersAndFromMeta()
"key7", "valueFromScenarioMeta7",
CapabilityType.PROXY, proxyMock,
OUTER_KEY, Map.of(INNER_KEY, parameterValue)),
vividusWebDriver.getDesiredCapabilities().asMap());
factory.desiredCapabilities.asMap());
InOrder ordered = Mockito.inOrder(webDriverStartContext, runContext);
ordered.verify(webDriverStartContext).get(WebDriverStartParameters.DESIRED_CAPABILITIES);
ordered.verify(runContext).getRunningStory();
Expand All @@ -146,7 +146,7 @@ void shouldCreateDriverWithoutMetaCapabilities()
VividusWebDriver vividusWebDriver = factory.create();

assertFalse(vividusWebDriver.isRemote());
assertEquals(Map.of(KEY1, value), vividusWebDriver.getDesiredCapabilities().asMap());
assertEquals(Map.of(KEY1, value), factory.desiredCapabilities.asMap());
InOrder ordered = Mockito.inOrder(webDriverStartContext, runContext);
ordered.verify(webDriverStartContext).get(WebDriverStartParameters.DESIRED_CAPABILITIES);
ordered.verify(runContext).getRunningStory();
Expand All @@ -170,6 +170,8 @@ private Meta metaOf(String... properties)

private final class TestVividusWebDriverFactory extends AbstractVividusWebDriverFactory
{
private DesiredCapabilities desiredCapabilities;

private TestVividusWebDriverFactory(boolean remoteExecution, WebDriverStartContext webDriverStartContext,
RunContext runContext, IProxy proxy,
Optional<Set<DesiredCapabilitiesConfigurer>> desiredCapabilitiesConfigurers)
Expand All @@ -180,6 +182,7 @@ private TestVividusWebDriverFactory(boolean remoteExecution, WebDriverStartConte
@Override
protected WebDriver createWebDriver(DesiredCapabilities desiredCapabilities)
{
this.desiredCapabilities = desiredCapabilities;
return webDriver;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

class VividusWebDriverTests
{
Expand All @@ -49,12 +48,4 @@ void testGetSetIsRemote()
vividusWebDriver.setRemote(true);
assertTrue(vividusWebDriver.isRemote());
}

@Test
void testGetSetDesiredCapabilities()
{
DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class);
vividusWebDriver.setDesiredCapabilities(desiredCapabilities);
assertEquals(desiredCapabilities, vividusWebDriver.getDesiredCapabilities());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -146,7 +146,7 @@ void testPerformActionInNativeContextSwitchNotNeeded()
verify(contextSwitchingDriver, never()).getContextHandles();
}

static Stream<Arguments> mobileArguments()
static Stream<Arguments> platformsData()
{
// CHECKSTYLE:OFF
return Stream.of(
Expand All @@ -167,13 +167,19 @@ static Stream<Arguments> mobileArguments()
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isTvOS, MobilePlatform.TVOS, true),
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isTvOS, MobilePlatform.IOS, false),
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isTvOS, Platform.IOS, false),
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isIOS, null, false)
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isIOS, null, false),
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isMacOs, Platform.MAC, true),
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isMacOs, Platform.WINDOWS, false),
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isMacOs, Platform.LINUX, false),
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isMacOs, Platform.UNIX, false),
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isMacOs, Platform.IOS, false),
arguments((Predicate<GenericWebDriverManager>) GenericWebDriverManager::isMacOs, null, false)
);
// CHECKSTYLE:ON
}

@ParameterizedTest
@MethodSource("mobileArguments")
@MethodSource("platformsData")
void testIsPlatform(Predicate<GenericWebDriverManager> test, Object platform, boolean expected)
{
mockWebDriver(platform);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -76,7 +76,7 @@ private Path createExcelFile() throws IOException
return ResourceUtils.createTempFile("test", ".xlsx", null);
}

@SuppressWarnings("checkstyle:MultipleStringLiteralsExtended")
@SuppressWarnings({ "checkstyle:MultipleStringLiterals", "checkstyle:MultipleStringLiteralsExtended" })
private void assertDataInSheet(Path path, int index, String name) throws IOException
{
try (XSSFWorkbook myExcelBook = new XSSFWorkbook(FileUtils.openInputStream(new File(path.toString()))))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,10 @@

package org.vividus.ui.web.action;

import static java.util.Map.entry;

import java.util.List;
import java.util.Map.Entry;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
Expand Down Expand Up @@ -100,7 +103,10 @@ public void clearFieldUsingKeyboard(WebElement field)
{
if (field != null)
{
field.sendKeys(Keys.chord(Keys.CONTROL, "a") + Keys.BACK_SPACE);
Entry<Keys, String> controllingKey = webDriverManager.isMacOs() ? entry(Keys.COMMAND, "Cmd")
: entry(Keys.CONTROL, "Ctrl");
LOGGER.info("Attempting to clear field with [{} + A, Backspace] keys sequence", controllingKey.getValue());
field.sendKeys(Keys.chord(controllingKey.getKey(), "a") + Keys.BACK_SPACE);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,9 @@

package org.vividus.ui.web.action;

import static com.github.valfirst.slf4jtest.LoggingEvent.info;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
Expand All @@ -27,9 +30,14 @@

import java.util.List;

import com.github.valfirst.slf4jtest.TestLogger;
import com.github.valfirst.slf4jtest.TestLoggerFactory;
import com.github.valfirst.slf4jtest.TestLoggerFactoryExtension;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.InOrder;
import org.mockito.InjectMocks;
Expand All @@ -45,7 +53,7 @@
import org.vividus.softassert.ISoftAssert;
import org.vividus.ui.web.util.FormatUtils;

@ExtendWith(MockitoExtension.class)
@ExtendWith({ MockitoExtension.class, TestLoggerFactoryExtension.class })
class FieldActionsTests
{
private static final String INDEX = "index";
Expand All @@ -69,6 +77,8 @@ class FieldActionsTests
@Mock private IWebWaitActions waitActions;
@InjectMocks private FieldActions fieldActions;

private final TestLogger logger = TestLoggerFactory.getTestLogger(FieldActions.class);

@Test
void testSelectItemInDDLSelectPresentOptionExist()
{
Expand Down Expand Up @@ -167,11 +177,18 @@ void testSelectItemInDDLSingleSelectAdditable()
.recordFailedAssertion("Multiple selecting is not available to single select drop down");
}

@Test
void testClearFieldUsingKeyboard()
@ParameterizedTest
@CsvSource({
"false, CONTROL, Ctrl",
"true, COMMAND, Cmd"
})
void testClearFieldUsingKeyboard(boolean macOs, Keys controllingKey, String controllingKeyName)
{
when(webDriverManager.isMacOs()).thenReturn(macOs);
fieldActions.clearFieldUsingKeyboard(webElement);
verify(webElement).sendKeys(Keys.chord(Keys.CONTROL, "a") + Keys.BACK_SPACE);
verify(webElement).sendKeys(Keys.chord(controllingKey, "a") + Keys.BACK_SPACE);
assertThat(logger.getLoggingEvents(), is(List.of(
info("Attempting to clear field with [{} + A, Backspace] keys sequence", controllingKeyName))));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variables.scope-priority-check=should be global
batch-1.variables.scope-priority-check=should be batch

# This property is used to test HTTP retry on service unavailability
http.service-unavailable-retry.status-codes=418
http.service-unavailable-retry.status-codes=418,504
http.service-unavailable-retry.max-retries=2

db.connection.csv-data.url=jdbc:relique:csv:classpath:data?separator=;&quoteStyle=C
Expand Down
2 changes: 1 addition & 1 deletion vividus-tests/src/main/resources/steps/composite.steps
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Composite: Then field value is `$expected`
Composite:Then field value is `$expected`
When I execute javascript `return document.querySelector('#text').value` and save result to scenario variable `fieldValue`
Then `${fieldValue}` is equal to `<expected>`

Expand Down

0 comments on commit 8065ea3

Please sign in to comment.