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

add clearBeforeTypingMode flag and deprecating old flags #1752

Merged
merged 3 commits into from
Oct 1, 2024
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
19 changes: 12 additions & 7 deletions src/main/java/com/shaft/gui/element/internal/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,20 @@
}
}
case TYPE -> {
if (SHAFT.Properties.flags.attemptClearBeforeTyping())
foundElements.get().getFirst().clear();
String clearMode = SHAFT.Properties.flags.clearBeforeTypingMode();
switch(clearMode){

Check warning on line 156 in src/main/java/com/shaft/gui/element/internal/Actions.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/java/com/shaft/gui/element/internal/Actions.java#L156

Switch statements should be exhaustive, add a default case (or missing enum branches)
case "native":
foundElements.get().getFirst().clear();
break ;
case "backspace":
String text = parseElementText(foundElements.get().getFirst());

Check warning on line 161 in src/main/java/com/shaft/gui/element/internal/Actions.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/gui/element/internal/Actions.java#L161

Added line #L161 was not covered by tests
if (!text.isEmpty())
foundElements.get().getFirst().sendKeys(String.valueOf(Keys.BACK_SPACE).repeat(text.length()));

Check warning on line 163 in src/main/java/com/shaft/gui/element/internal/Actions.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/gui/element/internal/Actions.java#L163

Added line #L163 was not covered by tests
break ;
case"off":
break;

if (SHAFT.Properties.flags.attemptClearBeforeTypingUsingBackspace()){
String text = parseElementText(foundElements.get().getFirst());
if (!text.isEmpty())
foundElements.get().getFirst().sendKeys(String.valueOf(Keys.BACK_SPACE).repeat(text.length()));
}

foundElements.get().getFirst().sendKeys((CharSequence) data);
}
case GET_NAME -> output.set(foundElements.get().getFirst().getAccessibleName());
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/com/shaft/properties/internal/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ private static void setProperty(String key, String value) {
@DefaultValue("true")
boolean attemptClearBeforeTyping();

@Key("clearBeforeTypingMode")
@DefaultValue("native")
String clearBeforeTypingMode();


@Key("forceCheckNavigationWasSuccessful")
@DefaultValue("false")
boolean forceCheckNavigationWasSuccessful();
Expand Down Expand Up @@ -126,17 +131,38 @@ public SetProperty forceCheckTextWasTypedCorrectly(boolean value) {
setProperty("forceCheckTextWasTypedCorrectly", String.valueOf(value));
return this;
}

/**
Please use {@link #clearBeforeTypingMode(String value)} instead.
*/
@Deprecated()
public SetProperty attemptClearBeforeTyping(boolean value) {
setProperty("attemptClearBeforeTyping", String.valueOf(value));
return this;
}

/**
Please use {@link #clearBeforeTypingMode(String value)} instead.
*/
@Deprecated
public SetProperty attemptClearBeforeTypingUsingBackspace(boolean value) {
setProperty("attemptClearBeforeTypingUsingBackspace", String.valueOf(value));
return this;
}

/**
*
* @param value
* <ul>
* <li><b>native</b> = clear using native Selenium method</li>
* <li><b>backspace</b> = clear by deleting letter by letter</li>
* <li><b>off</b> = no clearing</li>
* </ul>
*/
public SetProperty clearBeforeTypingMode(String value) {
setProperty("clearBeforeTypingMode", value);
return this;
}

public SetProperty forceCheckNavigationWasSuccessful(boolean value) {
setProperty("forceCheckNavigationWasSuccessful", String.valueOf(value));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.commons.lang3.SystemUtils;
import org.openqa.selenium.remote.Browser;

import java.awt.*;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
Expand Down Expand Up @@ -68,16 +69,28 @@
overrideScreenshotTypeForSafariBrowser();
overrideScreenshotTypeForParallelExecution();
setExtraAllureProperties();
setClearBeforeTypingMode();
}

private static void setClearBeforeTypingMode(){
if (!Properties.flags.attemptClearBeforeTyping() || SHAFT.Properties.flags.clearBeforeTypingMode().equals("off")) {
SHAFT.Properties.flags.set().clearBeforeTypingMode("off");
return ;
}

if (Properties.flags.attemptClearBeforeTypingUsingBackspace() || SHAFT.Properties.flags.clearBeforeTypingMode().equals("backspace")) {
SHAFT.Properties.flags.set().clearBeforeTypingMode("backspace");

Check warning on line 82 in src/main/java/com/shaft/properties/internal/PropertiesHelper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/properties/internal/PropertiesHelper.java#L82

Added line #L82 was not covered by tests
}
}

private static void overrideScreenshotTypeForParallelExecution() {
if (!Properties.testNG.parallel().equals("NONE"))
SHAFT.Properties.visuals.set().screenshotParamsScreenshotType(String.valueOf(Screenshots.VIEWPORT));
}

private static void overrideScreenScalingFactorForWindows() {
if (Properties.platform.targetPlatform().equalsIgnoreCase(org.openqa.selenium.Platform.WINDOWS.toString())) {
int res = java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
int res = Toolkit.getDefaultToolkit().getScreenResolution();

Check warning on line 93 in src/main/java/com/shaft/properties/internal/PropertiesHelper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/properties/internal/PropertiesHelper.java#L93

Added line #L93 was not covered by tests
double scale = (double)res/96;
Properties.visuals.set().screenshotParamsScalingFactor(scale);
}
Expand Down
Loading