-
-
Notifications
You must be signed in to change notification settings - Fork 492
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 #49 from ZhouYixun/dev
v1.1.0
- Loading branch information
Showing
18 changed files
with
635 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,7 @@ | |
/test-output/ | ||
/target/ | ||
/.gradle/ | ||
/logs/ | ||
*.iml | ||
*/.DS_Store | ||
.DS_Store |
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
Binary file not shown.
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
77 changes: 77 additions & 0 deletions
77
src/main/java/com/sonic/agent/automation/RemoteDebugDriver.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,77 @@ | ||
package com.sonic.agent.automation; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.sonic.agent.tools.PortTool; | ||
import org.mitre.dsmiley.httpproxy.ProxyServlet; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.DependsOn; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.servlet.Servlet; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author ZhouYiXun | ||
* @des | ||
* @date 2021/10/29 0:28 | ||
*/ | ||
@Configuration | ||
public class RemoteDebugDriver { | ||
private static String chromePath; | ||
public static int port = 0; | ||
public static WebDriver webDriver; | ||
@Value("${sonic.chrome.path}") | ||
private String path; | ||
|
||
@Bean | ||
public void setChromePath() { | ||
chromePath = path; | ||
} | ||
|
||
@Bean | ||
public Servlet baiduProxyServlet() { | ||
return new ProxyServlet(); | ||
} | ||
|
||
@Bean | ||
@DependsOn(value = "startChromeDriver") | ||
public ServletRegistrationBean proxyServletRegistration() { | ||
ServletRegistrationBean registrationBean = new ServletRegistrationBean(baiduProxyServlet(), "/agent/*"); | ||
Map<String, String> params = ImmutableMap.of( | ||
"targetUri", "http://localhost:" + port + "/devtools", | ||
"log", "false"); | ||
registrationBean.setInitParameters(params); | ||
return registrationBean; | ||
} | ||
|
||
@Bean | ||
@DependsOn(value = "setChromePath") | ||
public static void startChromeDriver() { | ||
DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); | ||
ChromeOptions chromeOptions = new ChromeOptions(); | ||
System.setProperty("webdriver.chrome.driver", chromePath); | ||
if (port == 0) { | ||
int debugPort = PortTool.getPort(); | ||
port = debugPort; | ||
chromeOptions.addArguments("--remote-debugging-port=" + debugPort); | ||
} else { | ||
chromeOptions.addArguments("--remote-debugging-port=" + port); | ||
} | ||
chromeOptions.addArguments("--headless"); | ||
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); | ||
webDriver = new ChromeDriver(desiredCapabilities); | ||
} | ||
|
||
public static void close() { | ||
if (webDriver != null) { | ||
webDriver.quit(); | ||
} | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/sonic/agent/exception/SonicException.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,12 @@ | ||
package com.sonic.agent.exception; | ||
|
||
/** | ||
* @author ZhouYiXun | ||
* @des | ||
* @date 2021/10/10 11:57 | ||
*/ | ||
public class SonicException extends Exception { | ||
public SonicException(String message) { | ||
super(message); | ||
} | ||
} |
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
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
Oops, something went wrong.