Skip to content

Commit 66b42a2

Browse files
author
Daniil Tsarev
committed
Table.selectRows() doesn't work on MacOS #23
1 parent 620c46c commit 66b42a2

File tree

2 files changed

+69
-8
lines changed

2 files changed

+69
-8
lines changed

modules/web/src/main/java/com/haulmont/masquerade/components/impl/DataGridImpl.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.haulmont.masquerade.components.DataGrid;
99
import com.haulmont.masquerade.conditions.SpecificCondition;
1010
import org.openqa.selenium.By;
11+
import org.openqa.selenium.JavascriptExecutor;
1112
import org.openqa.selenium.Keys;
1213
import org.openqa.selenium.WebDriver;
1314
import org.openqa.selenium.interactions.Actions;
@@ -27,6 +28,7 @@
2728
import static com.haulmont.masquerade.Conditions.VISIBLE;
2829
import static com.haulmont.masquerade.Selectors.byChain;
2930
import static com.haulmont.masquerade.Selectors.byCubaId;
31+
import static com.haulmont.masquerade.components.impl.TableImpl.MAC_OS_PLATFORM;
3032
import static com.haulmont.masquerade.sys.VaadinClassNames.selectedClass;
3133
import static com.haulmont.masquerade.sys.matchers.ConditionCases.componentApply;
3234
import static com.haulmont.masquerade.sys.matchers.InstanceOfCases.hasType;
@@ -270,9 +272,11 @@ public SelenideElement deselectRow(By rowBy) {
270272
WebDriver webDriver = WebDriverRunner.getWebDriver();
271273
Actions action = new Actions(webDriver);
272274

273-
action.keyDown(Keys.CONTROL)
275+
Keys controlKey = getControlKey();
276+
277+
action.keyDown(controlKey)
274278
.click(row.getWrappedElement())
275-
.keyUp(Keys.CONTROL)
279+
.keyUp(controlKey)
276280
.build()
277281
.perform();
278282

@@ -293,9 +297,11 @@ public ElementsCollection selectRows(By rowBy) {
293297
for (SelenideElement row : rows) {
294298
row.shouldNotHave(selectedClass);
295299

296-
action.keyDown(Keys.CONTROL)
300+
Keys controlKey = getControlKey();
301+
302+
action.keyDown(controlKey)
297303
.click(row.getWrappedElement())
298-
.keyUp(Keys.CONTROL)
304+
.keyUp(controlKey)
299305
.build()
300306
.perform();
301307
}
@@ -415,4 +421,28 @@ protected int getSortClickCount(DataGrid.SortDirection current, DataGrid.SortDir
415421

416422
return 2;
417423
}
424+
425+
/**
426+
* @return control key depending on operating system
427+
*/
428+
protected Keys getControlKey() {
429+
Keys controlKey = Keys.CONTROL;
430+
431+
WebDriver webDriver = WebDriverRunner.getWebDriver();
432+
if (webDriver instanceof JavascriptExecutor) {
433+
// check if working on MacOS
434+
Object result = ((JavascriptExecutor) webDriver)
435+
.executeScript("return window.navigator.platform");
436+
437+
if (result instanceof String) {
438+
String platform = (String) result;
439+
440+
if (MAC_OS_PLATFORM.equals(platform)) {
441+
controlKey = Keys.COMMAND;
442+
}
443+
}
444+
}
445+
446+
return controlKey;
447+
}
418448
}

modules/web/src/main/java/com/haulmont/masquerade/components/impl/TableImpl.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.haulmont.masquerade.conditions.SpecificCondition;
2626
import com.haulmont.masquerade.sys.TagNames;
2727
import org.openqa.selenium.By;
28+
import org.openqa.selenium.JavascriptExecutor;
2829
import org.openqa.selenium.Keys;
2930
import org.openqa.selenium.WebDriver;
3031
import org.openqa.selenium.interactions.Actions;
@@ -50,6 +51,8 @@
5051

5152
public class TableImpl extends AbstractComponent<Table> implements Table {
5253

54+
public static final String MAC_OS_PLATFORM = "MacIntel";
55+
5356
public TableImpl(By by) {
5457
super(by);
5558
}
@@ -286,9 +289,11 @@ public SelenideElement deselectRow(By rowBy) {
286289
WebDriver webDriver = WebDriverRunner.getWebDriver();
287290
Actions action = new Actions(webDriver);
288291

289-
action.keyDown(Keys.CONTROL)
292+
Keys controlKey = getControlKey();
293+
294+
action.keyDown(controlKey)
290295
.click(row.getWrappedElement())
291-
.keyUp(Keys.CONTROL)
296+
.keyUp(controlKey)
292297
.build()
293298
.perform();
294299

@@ -309,9 +314,11 @@ public ElementsCollection selectRows(By rowBy) {
309314
for (SelenideElement row : rows) {
310315
row.shouldNotHave(selectedClass);
311316

312-
action.keyDown(Keys.CONTROL)
317+
Keys controlKey = getControlKey();
318+
319+
action.keyDown(controlKey)
313320
.click(row.getWrappedElement())
314-
.keyUp(Keys.CONTROL)
321+
.keyUp(controlKey)
315322
.build()
316323
.perform();
317324
}
@@ -412,4 +419,28 @@ protected int getSortClickCount(SortDirection current, SortDirection target) {
412419

413420
return 2;
414421
}
422+
423+
/**
424+
* @return control key depending on operating system
425+
*/
426+
protected Keys getControlKey() {
427+
Keys controlKey = Keys.CONTROL;
428+
429+
WebDriver webDriver = WebDriverRunner.getWebDriver();
430+
if (webDriver instanceof JavascriptExecutor) {
431+
// check if working on MacOS
432+
Object result = ((JavascriptExecutor) webDriver)
433+
.executeScript("return window.navigator.platform");
434+
435+
if (result instanceof String) {
436+
String platform = (String) result;
437+
438+
if (MAC_OS_PLATFORM.equals(platform)) {
439+
controlKey = Keys.COMMAND;
440+
}
441+
}
442+
}
443+
444+
return controlKey;
445+
}
415446
}

0 commit comments

Comments
 (0)