-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from sam80180/main
fix: support W3C touch actions (for WDA version >= 7.0.0)
- Loading branch information
Showing
8 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/org/cloud/sonic/driver/common/models/WDAStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.cloud.sonic.driver.common.models; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@ToString | ||
@AllArgsConstructor | ||
public class WDAStatus { | ||
private WDABuild build; | ||
|
||
@Getter | ||
@ToString | ||
@AllArgsConstructor | ||
public static class WDABuild { | ||
private String version; | ||
} // end class | ||
} // end class | ||
|
||
/* | ||
References: | ||
https://github.com/SonicCloudOrg/sonic-driver-core/blob/faa0948e11e02be04db3ec9754fb66d613cf8bfa/src/main/java/org/cloud/sonic/driver/ios/service/impl/WdaClientImpl.java#L128 | ||
*/ |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/cloud/sonic/driver/common/tool/SemanticVersionTools.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.cloud.sonic.driver.common.tool; | ||
|
||
import com.github.zafarkhaja.semver.Version; | ||
|
||
public class SemanticVersionTools { | ||
public static Version parseSemVer(final String s) { | ||
return Version.parse(s); | ||
} // end parseSemVer() | ||
|
||
public static Version getVersionCore(final Version v) { | ||
return Version.of(v.majorVersion(), v.minorVersion(), v.patchVersion()); | ||
} // end getVersionCore() | ||
|
||
public static String pad4SemVer(final String s) { | ||
if (Version.isValid(s)) { return s; } // end if | ||
final String p[] = s.split("\\."); | ||
final String vv[] = new String[] {"0", "0", "0"}; | ||
for (int i=0; i<3; i++) { | ||
try { | ||
vv[i] = String.format("%d", Integer.parseInt(p[i], 10)); | ||
} catch (Exception e) {} // end try | ||
} // end for | ||
return String.join(".", vv); | ||
} // end pad4SemVer() | ||
} // end class |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/cloud/sonic/driver/common/tool/StringTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.cloud.sonic.driver.common.tool; | ||
|
||
import java.util.UUID; | ||
|
||
public class StringTool { | ||
private static String[] CHARS = new String[] { | ||
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", | ||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", | ||
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" | ||
}; | ||
|
||
public static String generateShortUuid() { // http://www.java2s.com/example/java-utility-method/uuid-create/generateshortuuid-db743.html | ||
StringBuilder shortBuilder = new StringBuilder(); | ||
String uuid = UUID.randomUUID().toString().replace("-", ""); | ||
for (int i=0; i<8; i++) { | ||
String str = uuid.substring(i*4, i*4+4); | ||
int x = Integer.parseInt(str, 16); | ||
shortBuilder.append(CHARS[x%0x3E]); | ||
} // end for | ||
return shortBuilder.toString(); | ||
} // end generateShortUuid() | ||
} // end class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/org/cloud/sonic/driver/ios/models/W3CActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.cloud.sonic.driver.ios.models; | ||
|
||
import java.time.Duration; | ||
import org.cloud.sonic.driver.common.tool.StringTool; | ||
import org.cloud.sonic.driver.ios.enums.ActionType; | ||
import org.cloud.sonic.driver.ios.models.TouchActions.TouchAction; | ||
import org.cloud.sonic.driver.ios.models.TouchActions.TouchAction.Options; | ||
import org.openqa.selenium.interactions.Pause; | ||
import org.openqa.selenium.interactions.PointerInput; | ||
import org.openqa.selenium.interactions.Sequence; | ||
import org.openqa.selenium.interactions.PointerInput.Kind; | ||
import org.openqa.selenium.interactions.PointerInput.MouseButton; | ||
import org.openqa.selenium.interactions.PointerInput.Origin; | ||
|
||
public class W3CActions { | ||
public static Sequence convert(final TouchActions touchActions) { | ||
final PointerInput FINGER = new PointerInput(Kind.TOUCH, "finger-"+StringTool.generateShortUuid()); | ||
final Sequence seq = new Sequence(FINGER, 0 /* https://github.com/appium/appium/issues/11273#issuecomment-416636734 */); | ||
for (TouchAction action: touchActions.getActions()) { | ||
final String strAction = action.getAction(); | ||
final Options actionData = action.getOptions(); | ||
if (strAction.equals(ActionType.MOVE.getType())) { | ||
final Integer optMs = actionData.getMs(); | ||
final long ms = (optMs==null ? 0 : Math.max(optMs, 0)); | ||
seq.addAction(FINGER.createPointerMove(Duration.ofMillis(ms), Origin.viewport(), actionData.getX(), actionData.getY())); | ||
} else if (strAction.equals(ActionType.PRESS.getType())) { | ||
final Integer optMs = actionData.getMs(); | ||
final long ms = (optMs==null ? 0 : Math.max(optMs, 0)); | ||
seq.addAction(FINGER.createPointerMove(Duration.ofMillis(ms), Origin.viewport(), actionData.getX(), actionData.getY())); | ||
seq.addAction(FINGER.createPointerDown(MouseButton.LEFT.asArg())); | ||
} else if (strAction.equals(ActionType.RELEASE.getType())) { | ||
seq.addAction(FINGER.createPointerUp(MouseButton.LEFT.asArg())); | ||
} else if (strAction.equals(ActionType.WAIT.getType())) { | ||
final Integer optMs = actionData.getMs(); | ||
final long ms = (optMs==null ? 0 : Math.max(optMs, 0)); | ||
if (ms<=0) { continue; } // end if | ||
seq.addAction(new Pause(FINGER, Duration.ofMillis(ms))); | ||
} // end if | ||
} // end for | ||
return seq; | ||
} // end convert() | ||
} // end class | ||
|
||
/* | ||
References: | ||
https://stackoverflow.com/a/71038411/12857692 | ||
https://github.com/appium/appium-espresso-driver/issues/244 | ||
https://github.com/appium/appium/issues/11273 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters