Skip to content

Commit

Permalink
feat: merge common
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Sep 13, 2022
1 parent 8e9e9dc commit 49b2675
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) [SonicCloudOrg] Sonic Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.cloud.sonic.driver.android.service;

import com.alibaba.fastjson.JSONObject;
import org.cloud.sonic.driver.tool.RespHandler;
import org.cloud.sonic.driver.tool.Logger;
import org.cloud.sonic.driver.tool.SonicRespException;

/**
* @author Eason
* uia client interface
*/
public interface UiaClient {
//Client Setting
void setGlobalTimeOut(int timeOut);

RespHandler getRespHandler();

void setRespHandler(RespHandler respHandler);

Logger getLogger();

void showLog();

void disableLog();

//Session handler.
String getRemoteUrl();

void setRemoteUrl(String remoteUrl);

String getSessionId();

void setSessionId(String sessionId);

void newSession(JSONObject capabilities) throws SonicRespException;

void closeSession() throws SonicRespException;

void checkSessionId() throws SonicRespException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) [SonicCloudOrg] Sonic Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.cloud.sonic.driver.android.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.cloud.sonic.driver.android.service.UiaClient;
import org.cloud.sonic.driver.tool.RespHandler;
import org.cloud.sonic.driver.ios.models.WindowSize;
import org.cloud.sonic.driver.tool.Logger;
import org.cloud.sonic.driver.tool.SonicRespException;

public class UiaClientImpl implements UiaClient {
private String remoteUrl;
private String sessionId;
private RespHandler respHandler;
private Logger logger;
private WindowSize size;

public UiaClientImpl() {
respHandler = new RespHandler();
logger = new Logger();
}

@Override
public void setGlobalTimeOut(int timeOut) {
respHandler.setRequestTimeOut(timeOut);
}

@Override
public RespHandler getRespHandler() {
return null;
}

@Override
public void setRespHandler(RespHandler respHandler) {

}

@Override
public Logger getLogger() {
return null;
}

@Override
public void showLog() {

}

@Override
public void disableLog() {

}

@Override
public String getRemoteUrl() {
return null;
}

@Override
public void setRemoteUrl(String remoteUrl) {

}

@Override
public String getSessionId() {
return null;
}

@Override
public void setSessionId(String sessionId) {

}

@Override
public void newSession(JSONObject capabilities) throws SonicRespException {

}

@Override
public void closeSession() throws SonicRespException {

}

@Override
public void checkSessionId() throws SonicRespException {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
package org.cloud.sonic.driver.ios.models;
package org.cloud.sonic.driver.common.models;

import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
package org.cloud.sonic.driver.ios.models;
package org.cloud.sonic.driver.common.models;

import lombok.AllArgsConstructor;
import lombok.ToString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
package org.cloud.sonic.driver.ios.models;
package org.cloud.sonic.driver.common.models;

import lombok.AllArgsConstructor;
import lombok.ToString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
package org.cloud.sonic.driver.ios.models;
package org.cloud.sonic.driver.common.models;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.cloud.sonic.driver.common.service;

import com.alibaba.fastjson.JSONObject;
import org.cloud.sonic.driver.ios.models.TouchActions;
import org.cloud.sonic.driver.ios.models.WindowSize;
import org.cloud.sonic.driver.ios.service.WebElement;
import org.cloud.sonic.driver.tool.Logger;
import org.cloud.sonic.driver.tool.RespHandler;
import org.cloud.sonic.driver.tool.SonicRespException;

import java.util.List;

public interface BaseClient {
//Client Setting
void setGlobalTimeOut(int timeOut);

RespHandler getRespHandler();

void setRespHandler(RespHandler respHandler);

Logger getLogger();

void showLog();

void disableLog();

//Session handler.
String getRemoteUrl();

void setRemoteUrl(String remoteUrl);

String getSessionId();

void setSessionId(String sessionId);

void newSession(JSONObject capabilities) throws SonicRespException;

void closeSession() throws SonicRespException;

void checkSessionId() throws SonicRespException;

//window handler.
WindowSize getWindowSize() throws SonicRespException;

//lock handler.
boolean isLocked() throws SonicRespException;

void lock() throws SonicRespException;

void unlock() throws SonicRespException;

//perform handler.
void performTouchAction(TouchActions touchActions) throws SonicRespException;

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

//keyboard handler.
void sendKeys(String text, Integer frequency) throws SonicRespException;

void setPasteboard(String contentType, String content) throws SonicRespException;

byte[] getPasteboard(String contentType) throws SonicRespException;

//source handler.
String pageSource() throws SonicRespException;

//siri handler.
void sendSiriCommand(String command) throws SonicRespException;

//app handler.
void appActivate(String bundleId) throws SonicRespException;

boolean appTerminate(String bundleId) throws SonicRespException;

void appRunBackground(int duration) throws SonicRespException;

void appAuthReset(int resource) throws SonicRespException;

//element handler.
void setDefaultFindElementInterval(Integer retry, Integer interval);

WebElement findElement(String selector, String value, Integer retry, Integer interval) throws SonicRespException;

List<WebElement> findElementList(String selector, String value, Integer retry, Integer interval) throws SonicRespException;

//screen handler.
byte[] screenshot() throws SonicRespException;

//appium setting handler.
void setAppiumSettings(JSONObject settings) throws SonicRespException;
}
1 change: 1 addition & 0 deletions src/main/java/org/cloud/sonic/driver/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.cloud.sonic.driver.ios.service.WdaClient;
import org.cloud.sonic.driver.ios.service.WebElement;
import org.cloud.sonic.driver.ios.service.impl.WdaClientImpl;
import org.cloud.sonic.driver.tool.RespHandler;
import org.cloud.sonic.driver.tool.SonicRespException;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package org.cloud.sonic.driver.ios.service;

import com.alibaba.fastjson.JSONObject;
import org.cloud.sonic.driver.ios.RespHandler;
import org.cloud.sonic.driver.common.service.BaseClient;
import org.cloud.sonic.driver.tool.RespHandler;
import org.cloud.sonic.driver.ios.models.TouchActions;
import org.cloud.sonic.driver.ios.models.WindowSize;
import org.cloud.sonic.driver.tool.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import cn.hutool.http.Method;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.cloud.sonic.driver.ios.RespHandler;
import org.cloud.sonic.driver.ios.models.BaseResp;
import org.cloud.sonic.driver.ios.models.SessionInfo;
import org.cloud.sonic.driver.tool.RespHandler;
import org.cloud.sonic.driver.common.models.BaseResp;
import org.cloud.sonic.driver.common.models.SessionInfo;
import org.cloud.sonic.driver.ios.models.TouchActions;
import org.cloud.sonic.driver.ios.models.WindowSize;
import org.cloud.sonic.driver.ios.service.WdaClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import org.cloud.sonic.driver.ios.models.BaseResp;
import org.cloud.sonic.driver.common.models.BaseResp;
import org.cloud.sonic.driver.ios.models.IOSRect;
import org.cloud.sonic.driver.ios.service.WdaClient;
import org.cloud.sonic.driver.ios.service.WebElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* limitations under the License.
*
*/
package org.cloud.sonic.driver.ios;
package org.cloud.sonic.driver.tool;

import cn.hutool.core.io.IORuntimeException;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.cloud.sonic.driver.ios.models.BaseResp;
import org.cloud.sonic.driver.ios.models.ErrorMsg;
import org.cloud.sonic.driver.android.service.UiaClient;
import org.cloud.sonic.driver.common.models.BaseResp;
import org.cloud.sonic.driver.common.models.ErrorMsg;
import org.cloud.sonic.driver.ios.service.WdaClient;
import org.cloud.sonic.driver.tool.SonicRespException;

Expand All @@ -42,7 +43,7 @@ public BaseResp getResp(HttpRequest httpRequest) throws SonicRespException {
}

public BaseResp getResp(HttpRequest httpRequest, int timeout) throws SonicRespException {
synchronized (WdaClient.class) {
synchronized (this) {
try {
return initResp(httpRequest.addHeaders(initHeader()).timeout(timeout).execute().body());
} catch (HttpException | IORuntimeException e) {
Expand All @@ -52,8 +53,8 @@ public BaseResp getResp(HttpRequest httpRequest, int timeout) throws SonicRespEx
}

public BaseResp initResp(String response) {
if (response.contains("traceback")) {
return initErrorMsg(response);
if (response.contains("traceback") || response.contains("stacktrace")) {
return initErrorMsg(response.replace("stacktrace","traceback"));
} else {
return JSON.parseObject(response, BaseResp.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cloud.sonic.driver.ios;

import cn.hutool.http.HttpUtil;
import org.cloud.sonic.driver.tool.RespHandler;
import org.cloud.sonic.driver.tool.SonicRespException;
import org.junit.Assert;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package org.cloud.sonic.driver.ios.service;

import com.alibaba.fastjson.JSONObject;
import org.cloud.sonic.driver.ios.RespHandler;
import org.cloud.sonic.driver.tool.RespHandler;
import org.cloud.sonic.driver.ios.enums.IOSSelector;
import org.cloud.sonic.driver.ios.models.BaseResp;
import org.cloud.sonic.driver.ios.models.ErrorMsg;
import org.cloud.sonic.driver.common.models.BaseResp;
import org.cloud.sonic.driver.common.models.ErrorMsg;
import org.cloud.sonic.driver.ios.enums.PasteboardType;
import org.cloud.sonic.driver.ios.models.TouchActions;
import org.cloud.sonic.driver.ios.service.impl.WdaClientImpl;
Expand Down

0 comments on commit 49b2675

Please sign in to comment.