Skip to content

Commit

Permalink
revert bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Aug 9, 2024
1 parent db6d0f3 commit 071f75c
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 196 deletions.
16 changes: 0 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,6 @@
<version>4.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.zafarkhaja</groupId>
<artifactId>java-semver</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>4.22.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.16</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/org/cloud/sonic/driver/common/models/WDAStatus.java

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/org/cloud/sonic/driver/common/tool/StringTool.java

This file was deleted.

30 changes: 1 addition & 29 deletions src/main/java/org/cloud/sonic/driver/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,10 @@
*/
package org.cloud.sonic.driver.ios;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.zafarkhaja.semver.Version;

import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;

import org.cloud.sonic.driver.common.enums.PasteboardType;
import org.cloud.sonic.driver.common.models.BaseResp;
import org.cloud.sonic.driver.common.models.ErrorMsg;
import org.cloud.sonic.driver.common.models.WDAStatus;
import org.cloud.sonic.driver.common.models.WindowSize;
import org.cloud.sonic.driver.common.tool.RespHandler;
import org.cloud.sonic.driver.common.tool.SemanticVersionTools;
import org.cloud.sonic.driver.common.tool.SonicRespException;
import org.cloud.sonic.driver.ios.enums.*;
import org.cloud.sonic.driver.ios.models.TouchActions;
Expand All @@ -46,7 +36,6 @@
*/
public class IOSDriver {
private WdaClient wdaClient;
private Version wdaVersion;

/**
* Init ios driver.
Expand Down Expand Up @@ -93,7 +82,6 @@ public IOSDriver(String url, int timeOut, JSONObject cap) throws SonicRespExcept
wdaClient.setRemoteUrl(url);
wdaClient.setGlobalTimeOut(timeOut);
wdaClient.newSession(cap);
this.wdaVersion = this.getWDAVersion();
}

/**
Expand Down Expand Up @@ -242,11 +230,7 @@ public void swipe(double fromX, double fromY, double toX, double toY, double dur
* @throws SonicRespException
*/
public void performTouchAction(TouchActions touchActions) throws SonicRespException {
if (this.wdaVersion.satisfies("<7.0.0")) {
this.wdaClient.performTouchAction(touchActions);
} else {
this.wdaClient.performW3CTouchAction(touchActions);
} // end if
wdaClient.performTouchAction(touchActions);
}

/**
Expand Down Expand Up @@ -715,16 +699,4 @@ public void rotate(Orientation orientation) throws SonicRespException {
public Orientation getRotate() throws SonicRespException {
return wdaClient.getRotate();
}

public Version getWDAVersion() throws SonicRespException {
this.wdaClient.checkSessionId();
final String url = this.wdaClient.getRemoteUrl()+"/status";
final BaseResp<?> b = this.wdaClient.getRespHandler().getResp(HttpUtil.createRequest(Method.GET, url));
if (b==null) { throw new SonicRespException("null response body"); } // end if
final ErrorMsg err = b.getErr();
if (err!=null) { throw new SonicRespException(err.getMessage()); } // end if
final String result = b.getValue().toString();
final WDAStatus sessionStatus = JSON.parseObject(result, WDAStatus.class);
return SemanticVersionTools.parseSemVer(SemanticVersionTools.pad4SemVer(sessionStatus.getBuild().getVersion()));
} // end getWDAVersion()
}
49 changes: 0 additions & 49 deletions src/main/java/org/cloud/sonic/driver/ios/models/W3CActions.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ public interface WdaClient {
//perform handler.
void performTouchAction(TouchActions touchActions) throws SonicRespException;

void performW3CTouchAction(final TouchActions touchActions) throws SonicRespException;

//button handler.
void pressButton(String buttonName) throws SonicRespException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@
import cn.hutool.http.Method;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.entity.ContentType;
import org.cloud.sonic.driver.common.models.BaseResp;
import org.cloud.sonic.driver.common.models.ErrorMsg;
import org.cloud.sonic.driver.common.models.SessionInfo;
import org.cloud.sonic.driver.common.models.WindowSize;
import org.cloud.sonic.driver.common.tool.Logger;
import org.cloud.sonic.driver.common.tool.RespHandler;
import org.cloud.sonic.driver.common.tool.SonicRespException;
import org.cloud.sonic.driver.ios.enums.Orientation;
import org.cloud.sonic.driver.ios.models.TouchActions;
import org.cloud.sonic.driver.ios.models.W3CActions;
import org.cloud.sonic.driver.ios.service.IOSElement;
import org.cloud.sonic.driver.ios.service.WdaClient;
import org.openqa.selenium.interactions.Sequence;
import org.jsoup.select.CombiningEvaluator;

import java.nio.charset.StandardCharsets;
import java.util.*;
Expand Down Expand Up @@ -217,18 +214,6 @@ public void performTouchAction(TouchActions touchActions) throws SonicRespExcept
throw new SonicRespException(b.getErr().getMessage());
}
}

@SuppressWarnings("serial")
@Override
public void performW3CTouchAction(final TouchActions touchActions) throws SonicRespException {
final Sequence seq = W3CActions.convert(touchActions);
final int timeoutUpdateSettings = 1500;
final String strAppiumSettingsURL = String.format("%s/session/%s/actions", this.remoteUrl, this.sessionId);
final JSONObject payload = new JSONObject();
payload.put("actions", new LinkedList<Map<String, Object>>() {{ add(seq.toJson()); }});
final byte[] rawPayload = payload.toJSONString().getBytes(StandardCharsets.UTF_8);
this.sendAppiumRequest(Method.POST, strAppiumSettingsURL, ContentType.APPLICATION_JSON.toString(), rawPayload, timeoutUpdateSettings);
} // end performW3CTouchAction()

@Override
public void pressButton(String buttonName) throws SonicRespException {
Expand Down Expand Up @@ -622,17 +607,4 @@ public Orientation getRotate() throws SonicRespException {
throw new SonicRespException(b.getErr().getMessage());
}
}

private void sendAppiumRequest(final Method method, final String url, final String contentType, final byte[] bodyBytes, final int timeout) throws SonicRespException {
this.checkSessionId();
final BaseResp<?> b = this.getRespHandler().getResp(HttpUtil.createRequest(method, url).body(bodyBytes).contentType(contentType), timeout);
if (b!=null) {
final ErrorMsg err = b.getErr();
if (err!=null) {
throw new SonicRespException(err.getMessage());
} // end if
} else {
throw new SonicRespException("null response body");
} // end if
} // end sendAppiumRequest()
}

0 comments on commit 071f75c

Please sign in to comment.