Skip to content

Commit 257d98e

Browse files
committed
squid:S1192 String literals should not be duplicated
1 parent e46309c commit 257d98e

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

src/main/java/org/sayem/webdriver/javascript/JavascriptActions.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
public class JavascriptActions extends DelegatingWebDriver
2020
implements ExplicitWait, SearchScope, JavascriptExecutor {
2121

22-
public static final String NO_JQUERY_ERROR = "ReferenceError: $ is not defined";
22+
private static final String J_QUERY_IS_NOT_DEFINED = "JQuery is not defined";
23+
private static final String JS_ERROR = "JSError";
24+
public static final String NO_JQUERY_ERROR = "ReferenceError: $ is not defined";
2325
Logger logger = getLogger(JavascriptActions.class);
2426
private WebDriver webDriver;
2527

@@ -97,7 +99,7 @@ public void scrollToElement(By elementBy) {
9799
webDriver.findElement(elementBy));
98100
} catch (WebDriverException e) {
99101
if (e.getMessage().contains(NO_JQUERY_ERROR)) {
100-
logger.info("JSError", "JQuery is not defined", false);
102+
logger.info(JS_ERROR, J_QUERY_IS_NOT_DEFINED, false);
101103
}
102104
}
103105
}
@@ -111,7 +113,7 @@ public void scrollToElement(WebElement element) {
111113
);
112114
} catch (WebDriverException e) {
113115
if (e.getMessage().contains(NO_JQUERY_ERROR)) {
114-
logger.info("JSError", "JQuery is not defined", false);
116+
logger.info(JS_ERROR, J_QUERY_IS_NOT_DEFINED, false);
115117
}
116118
}
117119
}
@@ -126,7 +128,7 @@ public void scrollToElement(WebElement element, int offset) {
126128
);
127129
} catch (WebDriverException e) {
128130
if (e.getMessage().contains(NO_JQUERY_ERROR)) {
129-
logger.info("JSError", "JQuery is not defined", false);
131+
logger.info(JS_ERROR, J_QUERY_IS_NOT_DEFINED, false);
130132
}
131133
}
132134
}

src/main/java/org/sayem/webdriver/selenium/Browser.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
public class Browser extends DelegatingWebDriver
2222
implements ExplicitWait, SearchScope {
2323

24-
public static final Logger log = getLogger(Browser.class);
24+
private static final String VALUE2 = "value";
25+
public static final Logger log = getLogger(Browser.class);
2526
private Action action;
2627
private JavascriptActions javascript;
2728
private MultiSelect select;
@@ -68,13 +69,13 @@ public void setInputTextLambda(Supplier<By> by, String value) {
6869
Element element = findElement(by);
6970
element.clear();
7071
element.sendKeys(value);
71-
assert value.equals(element.getAttribute("value"));
72+
assert value.equals(element.getAttribute(VALUE2));
7273
}
7374
);
7475
}
7576

7677
public String getInputText(Supplier<By> by) {
77-
return untilFound(by).getAttribute("value");
78+
return untilFound(by).getAttribute(VALUE2);
7879
}
7980

8081
public void setCheckboxValue(Supplier<By> by, boolean value) {
@@ -94,7 +95,7 @@ public void setRadio(Supplier<By> by, String value) {
9495
assert radiobuttons.size() >= 2;
9596

9697
for (WebElement e : radiobuttons) {
97-
if (e.getAttribute("value").equals(value)) {
98+
if (e.getAttribute(VALUE2).equals(value)) {
9899
e.click();
99100
return;
100101
}
@@ -110,7 +111,7 @@ public String getRadio(By by) {
110111

111112
for (WebElement e : radiobuttons) {
112113
if (Boolean.valueOf(e.getAttribute("checked"))) {
113-
return e.getAttribute("value");
114+
return e.getAttribute(VALUE2);
114115
}
115116
}
116117
return null;

src/main/java/org/sayem/webdriver/selenium/DatePicker.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@
99
*/
1010
public class DatePicker {
1111

12-
public String todayDate() {
12+
private static final String M_D_YYYY = "M/d/yyyy";
13+
14+
public String todayDate() {
1315
LocalDate date = LocalDate.now();
14-
return date.format(DateTimeFormatter.ofPattern("M/d/yyyy"));
16+
return date.format(DateTimeFormatter.ofPattern(M_D_YYYY));
1517
}
1618

1719
public String addNumberOfDayToDate(int days) {
1820
LocalDate date = LocalDate.now().plusDays(days);
19-
return date.format(DateTimeFormatter.ofPattern("M/d/yyyy"));
21+
return date.format(DateTimeFormatter.ofPattern(M_D_YYYY));
2022
}
2123

2224
public String addOneWeekToDate() {
2325
LocalDate date = LocalDate.now().plusWeeks(1);
24-
return date.format(DateTimeFormatter.ofPattern("M/d/yyyy"));
26+
return date.format(DateTimeFormatter.ofPattern(M_D_YYYY));
2527
}
2628

2729
public String addOneMonthToDate() {
2830
LocalDate date = LocalDate.now().plusMonths(1);
29-
return date.format(DateTimeFormatter.ofPattern("M/d/yyyy"));
31+
return date.format(DateTimeFormatter.ofPattern(M_D_YYYY));
3032
}
3133

3234
public String addNumberOfWeekDay(int workdays) {
@@ -39,7 +41,7 @@ public String addNumberOfWeekDay(int workdays) {
3941
++addedDays;
4042
}
4143
}
42-
return result.format(DateTimeFormatter.ofPattern("M/d/yyyy"));
44+
return result.format(DateTimeFormatter.ofPattern(M_D_YYYY));
4345
}
4446

4547
public String addNumberOfWeekDayInReverse(int workdays) {

src/main/java/org/sayem/webdriver/selenium/MultiSelect.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
public class MultiSelect extends DelegatingWebDriver
2020
implements ExplicitWait, SearchScope {
2121

22-
public MultiSelect(WebDriver delegate) {
22+
private static final String VALUE = "value";
23+
24+
public MultiSelect(WebDriver delegate) {
2325
super(delegate);
2426
}
2527

@@ -141,7 +143,7 @@ public List<String> getAllSelectedTexts(Supplier<By> by) {
141143

142144
public String getFirstSelectedValue(Supplier<By> by) {
143145
try {
144-
return new Select(findElement(by)).getFirstSelectedOption().getAttribute("value");
146+
return new Select(findElement(by)).getFirstSelectedOption().getAttribute(VALUE);
145147
} catch (NoSuchElementException e) {
146148
return null;
147149
}
@@ -150,7 +152,7 @@ public String getFirstSelectedValue(Supplier<By> by) {
150152
public List<String> getAllSelectedValues(Supplier<By> by) {
151153
return new Select(findElement(by)).getAllSelectedOptions()
152154
.stream()
153-
.map(option -> option.getAttribute("value"))
155+
.map(option -> option.getAttribute(VALUE))
154156
.collect(Collectors.toList());
155157
}
156158

@@ -183,7 +185,7 @@ public List<String> getAllTexts(Supplier<By> by) {
183185
public List<String> getAllValues(Supplier<By> by) {
184186
return new Select(findElement(by)).getOptions()
185187
.stream()
186-
.map(option -> option.getAttribute("value"))
188+
.map(option -> option.getAttribute(VALUE))
187189
.collect(Collectors.toList());
188190
}
189191

0 commit comments

Comments
 (0)