в моем приложении Springboot у меня есть контроллер с конечной точкой startTest, который вызывает тестовый пакет Selenium как jar. Test.jar -> Class TestSuite -> метод: LG0000001 использует WebDriver класс для имитации операций автоматизации в браузере (Chrome).
Оба упакованы как JAR и развернуты на Unix Сервер, такой как Test.jar и BackEnd.jar.
Я вызываю сервис startTest с chrome на windows, например:
10.233.233.235: 8080 / startTest / TestOther .jar / TestSuite / LG0000001
Это мой Backend Class:
@RestController
public class Controller {
@RequestMapping(value = {"/startTest/Test.jar/TestSuite/LG0000001"},method = RequestMethod.GET) //this is for example i run only one method inside class
public ResponseEntity<Esito> runTest(@PathVariable String jar, @PathVariable String class_name, @PathVariable Optional<String> test_name ) throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException, MalformedURLException, InstantiationException, IllegalArgumentException, InvocationTargetException {
ReportInnerTests listener = new ReportInnerTests(); // is a overwrite for listener
this.runOne(jar,class_name,test_name,listener); //method for run test on Test.jar
Map<String, String> summary= listener.getSummary();
HttpHeaders responseHeaders = new HttpHeaders();
Esito esito=new Esito();
esito.setSummary(summary);
return new ResponseEntity<Esito>(esito, responseHeaders, HttpStatus.OK);
}
public void runOne(String jar, String class_name, Optional<String> test_name, TestExecutionListener listener) throws ClassNotFoundException, NoSuchMethodException, MalformedURLException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Launcher launcher = LauncherFactory.create();
ClassLoader loader = URLClassLoader.newInstance(
new URL[] { new File(pathJars+"/"+jar).toURI().toURL() },
getClass().getClassLoader()
);
loader.getClass();
Class cls=Class.forName(class_name,true,loader);
Constructor constructor = cls.getConstructor();
constructor.newInstance();
LauncherDiscoveryRequest request;
if (test_name.isPresent()) {
Method m = cls.getMethod(test_name.get());
request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectMethod(cls,m))
.build();
}
else{
request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectClass(cls))
.build();
}
TestPlan testPlan = launcher.discover(request);
launcher.registerTestExecutionListeners(listener);
launcher.execute(request); //here I run Test and work well with other Test that don't use Selenium
}
classTest для селена это то, что работает, если я запускаю backend на моем p c с windows:
@ExtendWith(TestReporter.class)
public class TestSuite {
WebDriver driver;
Actions action;
JavascriptExecutor jse;
public TestSuite() {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/test_jar/chromedriver"); //here i load driver and work on Unix
driver = new ChromeDriver();
action = new Actions(driver);
jse = (JavascriptExecutor) driver;
}
@Test
public void LG0000001(){
driver.manage().window().maximize();
LoginTest.login(driver, "http://xxxxxx.xxx.yyy.pages/dashboard",
"axfas","str"); // this a test that use another my class that use "WebDriver"
};
Если я, например, запускаю другой тест с Junit, он работает хорошо, и я просматриваю результаты. Но когда я запускаю TestSelenium.jar, у меня появляется эта ошибка:
2020-04-09 16:10:40.548 ERROR 90384 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.reflect.InvocationTargetException] with root cause
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
Мой вопрос: могу ли я запустить TestSelenium на Unix, вызванном вызовом RestPost из windows:
10.233.233.235:8080/startTest/TestOther.jar/TestSuite/LG0000001
но я хочу просмотреть все операции автоматизации в браузере на Chrome на windows, где я его называю.
Возможно или все бесполезно ?? :-( С уважением