[英]Can we use Selenium or any other jars to get network response and validate
I have a requirement here that I need to verify the network response values using selenium & java.我在这里有一个要求,我需要使用 selenium 和 java 验证网络响应值。
It would be great if there is any code that could help me out.如果有任何代码可以帮助我,那就太好了。
The action that I want to perform (which is needed to be automated) is我要执行的操作(需要自动化)是
load the application https://www.ancestry.com加载应用程序https://www.ancestry.com
press F12 and go to network tab when application is loading加载应用程序时按 F12 并转到网络选项卡
select a respective network containing b/ss选择包含 b/ss 的相应网络
click on it and get the values in the query parameters单击它并获取查询参数中的值
I have highlighted them in the below image我在下图中突出显示了它们
Note: I need to perform this action for every click event that happen after the application is loaded.注意:我需要为应用程序加载后发生的每个点击事件执行此操作。
Is this possible in selenium这在硒中可能吗
This is the code that I tried to get the values recorded am I doing it right please help这是我试图记录值的代码我做得对吗请帮忙
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver",
new File(".").getCanonicalPath() + "\\WebDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.ancestry.com");
//capture(driver);
driver.quit();
}
public static void capture(WebDriver driver) throws IOException {
OutputStream logfile = new FileOutputStream(new File(new
File(".").getCanonicalPath() + "\\log.txt"), true);
PrintStream printlog = new PrintStream(logfile);
LogEntries logs = driver.manage().logs().get(LogType.PERFORMANCE);
for (LogEntry entry : logs) {
if (entry.toString().contains("\"type\":\"Img\""))
System.out.println(entry.toString());
printlog.append(new Date(entry.getTimestamp()) + " " + entry.toString() + " "
+ System.getProperty("line.separator"));
printlog.append(System.getProperty("line.separator"));
printlog.append(System.getProperty("line.separator"));
}
printlog.close();
}
We can get all the network logs using browser mob proxy我们可以使用浏览器 mob 代理获取所有网络日志
private static BrowserMobProxy proxy = new BrowserMobProxyServer();
public webLib(String browser) {
logReport.logMethodStart("Launch Application");
Proxy seleniumProxy = null;
proxy.start();
seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
if (browser.equalsIgnoreCase("chrome")) {
try {
System.setProperty("webdriver.chrome.driver",
new File(".").getCanonicalFile() + seperator + "WebDriver" + seperator + "chromeDriver.exe");
} catch (IOException e) {
e.printStackTrace();
}
ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.PROXY, seleniumProxy);
options.setAcceptInsecureCerts(true);
options.addArguments("--ignore-certificate-errors");
options.addArguments("--disable-popup-blocking");
options.addArguments("--no-sandbox");
options.addArguments("--no-sandbox");
driver = new ChromeDriver(options);
} else if (browser.equalsIgnoreCase("firefox")) {
}
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
if (driver != null) {
logReport.logStep(Status.PASS, "Browser launched successfully", driver);
}
}
You can reffer the following site https://www.swtestacademy.com/webdriver-browsermob-proxy/您可以参考以下站点https://www.swtestacademy.com/webdriver-browsermob-proxy/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.