Closed DongJu-Na closed 11 months ago
I don't think this is going to work because UIA2 driver does not support devtools websocket proxying. Maybe such feature could be implemented in the future. @DongJu-Na would you be able to help us with testing eventually?
of course. I need this feature. We need to tell you how to get active.
I have created a plugin to proxy devtools API from a mobile browser to the client machine. Please check https://github.com/mykola-mokhnach/appium-devtools-plugin
It also has a code example. Let me know if you face unexpected issues while working with it
Thank you. We will check as soon as possible and write an issue if there are any special issues.
This issue will be closed.
Lastly, let me ask you a question.
How can I call the request and response list?
How can I call the request and response list?
Not sure what you mean. Any examples?
package com.acp.AbusingCheckProject.job;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.v116.network.Network;
import org.openqa.selenium.devtools.v116.network.Network.GetResponseBodyResponse;
import org.openqa.selenium.devtools.v116.network.model.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.acp.AbusingCheckProject.entity.logTbl;
import com.acp.AbusingCheckProject.repository.LogTblRepository;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.bonigarcia.wdm.WebDriverManager;
@Component
public class NetworkMonitoring {
@Value("${chrome.driver}")
public String driverPath;
@Autowired
private LogTblRepository logTblRepository;
//@Scheduled(fixedRate = 3600000)
public void executeNetworkMonitoring() {
try {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
//options.setCapability("goog:chromeOptions", Map.of("w3c", false));
Map<String, Object> deviceMetrics = new HashMap<>();
deviceMetrics.put("width", 1078);
deviceMetrics.put("height", 924);
deviceMetrics.put("pixelRatio", 3.0);
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent", "Mozilla/5.0 (Linux; Android 8.0.0;" + "Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/67.0.3396.99 Mobile Safari/537.36");
options.setExperimentalOption("mobileEmulation", mobileEmulation);
WebDriver driver = new ChromeDriver(options);
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
DevTools devTools = ((ChromeDriver) driver).getDevTools();
devTools.createSession();
devTools.send(Network.clearBrowserCookies());
devTools.send(Network.setCacheDisabled(true));
devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
devTools.addListener(Network.requestWillBeSent(), entry -> {
Request request = entry.getRequest();
String requestUrl = request.getUrl();
if (requestUrl.contains("aa.js")) {
System.out.println("request " + requestUrl);
}
if (requestUrl.contains("aa.php")) {
try {
String responseContent = getResponseContent(requestUrl);
System.out.println("responseContent " + responseContent);
ObjectMapper om = new ObjectMapper();
Map<String,Object> jsonMap = om.readValue(returnStr(responseContent),Map.class);
logTbl logtbl = logTbl.builder()
.result(jsonMap.containsKey("result") ? (String) jsonMap.get("result") : "")
.logDate(LocalDateTime.now())
.build();
logTblRepository.save(logtbl);
driver.quit(); // WebDriver 종료
} catch (IOException e) {
e.printStackTrace();
}
}
});
// 사이트로 이동
driver.get("https://test.com/");
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getResponseContent(String url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("GET");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
return response.toString();
}
}
public String returnStr(String str){
String filteredJson = "";
try{
int start = str.indexOf("(");
int end = str.lastIndexOf(")");
filteredJson = str.substring(start + 1, end);
}catch (Exception e){
e.printStackTrace();
}
return filteredJson;
}
}
I would like to structure it similar to this code.
Do you have solution for this
In a PC environment, the browser was checked using Selenium.
Use this code using appium Is migration possible?
migration code...