Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RATEST-351: Add automated webdriver management #489

Merged
merged 4 commits into from Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions qaframework-bdd-tests/package.json
Expand Up @@ -3,8 +3,8 @@
"version": "0.1.0",
"private": true,
"engines": {
"node": ">=14.15.5",
"npm": ">=7.5.3"
"node": ">=16.20.0",
"npm": ">=8.19.4"
},
"scripts": {
"refappSelenium": "mvn test -Dcucumber.filter.tags='@selenium and not @initialSetup'",
Expand Down
85 changes: 0 additions & 85 deletions qaframework-bdd-tests/pom.xml
Expand Up @@ -72,91 +72,6 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>make-mac-chromedriver-executable</id>
<phase>process-test-classes</phase>
<configuration>
<target>
<chmod file="target/test-classes/chromedriver/mac/chromedriver" perm="755"/>
</target>
<failOnError>false</failOnError>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>make-linux-chromedriver-executable</id>
<phase>process-test-classes</phase>
<configuration>
<target>
<chmod file="target/test-classes/chromedriver/linux/chromedriver" perm="755"/>
</target>
<failOnError>false</failOnError>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>make-windows-chromedriver-executable</id>
<phase>process-test-classes</phase>
<configuration>
<target>
<chmod file="target/test-classes/chromedriver/windows/chromedriver" perm="755"/>
</target>
<failOnError>false</failOnError>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>make-mac-firefoxdriver-executable</id>
<phase>process-test-classes</phase>
<configuration>
<target>
<chmod file="target/test-classes/firefoxdriver/mac/geckodriver" perm="755"/>
</target>
<failOnError>false</failOnError>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>make-linux-firefoxdriver-executable</id>
<phase>process-test-classes</phase>
<configuration>
<target>
<chmod file="target/test-classes/firefoxdriver/linux/geckodriver" perm="755"/>
</target>
<failOnError>false</failOnError>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>make-windows-firefoxdriver-executable</id>
<phase>process-test-classes</phase>
<configuration>
<target>
<chmod file="target/test-classes/firefoxdriver/windows/geckodriver" perm="755"/>
</target>
<failOnError>false</failOnError>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
Expand Down
Expand Up @@ -14,20 +14,12 @@

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.vfs2.AllFileSelector;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.VFS;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestName;
Expand Down Expand Up @@ -199,9 +191,6 @@ protected LoginPage getLoginPage() {
}

WebDriver setupFirefoxDriver() {
if (StringUtils.isBlank(System.getProperty("webdriver.gecko.driver"))) {
System.setProperty("webdriver.gecko.driver", Thread.currentThread().getContextClassLoader().getResource(TestProperties.instance().getFirefoxDriverLocation()).getPath());
}
FirefoxOptions firefoxOptions = new FirefoxOptions();
if ("true".equals(TestProperties.instance().getHeadless())) {
firefoxOptions.addArguments("--headless");
Expand All @@ -211,53 +200,6 @@ WebDriver setupFirefoxDriver() {
}

WebDriver setupChromeDriver() {
URL chromedriverExecutable = null;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

String chromedriverExecutableFilename = null;
if (SystemUtils.IS_OS_MAC_OSX) {
chromedriverExecutableFilename = "chromedriver";
chromedriverExecutable = classLoader.getResource("chromedriver/mac/chromedriver");
} else if (SystemUtils.IS_OS_LINUX) {
chromedriverExecutableFilename = "chromedriver";
chromedriverExecutable = classLoader.getResource("chromedriver/linux/chromedriver");
} else if (SystemUtils.IS_OS_WINDOWS) {
chromedriverExecutableFilename = "chromedriver.exe";
chromedriverExecutable = classLoader.getResource("chromedriver/windows/chromedriver.exe");
}
String errmsg = "cannot find chromedriver executable";
String chromedriverExecutablePath = null;
if (chromedriverExecutable == null) {
System.err.println(errmsg);
Assert.fail(errmsg);
} else {
chromedriverExecutablePath = chromedriverExecutable.getPath();
// This ugly bit checks to see if the chromedriver file is inside a
// jar, and if so
// uses VFS to extract it to a temp directory.
if (chromedriverExecutablePath.contains(".jar!")) {
FileObject chromedriver_vfs;
try {
chromedriver_vfs = VFS.getManager().resolveFile(
chromedriverExecutable.toExternalForm());
File chromedriver_fs = new File(FileUtils.getTempDirectory(),
chromedriverExecutableFilename);
FileObject chromedriverUnzipped = VFS.getManager().toFileObject(chromedriver_fs);
chromedriverUnzipped.delete();
chromedriverUnzipped.copyFrom(chromedriver_vfs, new AllFileSelector());
chromedriverExecutablePath = chromedriver_fs.getPath();
if (!SystemUtils.IS_OS_WINDOWS) {
chromedriver_fs.setExecutable(true);
}
} catch (FileSystemException e) {
System.err.println(errmsg + ": " + e);
e.printStackTrace();
Assert.fail(errmsg + ": " + e);
}
}
}
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
chromedriverExecutablePath);
String chromedriverFilesDir = "target/chromedriverlogs";
try {
FileUtils.forceMkdir(new File(chromedriverFilesDir));
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Expand Up @@ -4,5 +4,4 @@ login.password=Admin123
login.location=Pharmacy
webdriver=chrome
headless=true
webdriver.gecko.driver=firefoxdriver/linux/geckodriver
includes.csrftoken=true
Expand Up @@ -6,5 +6,4 @@ webdriver=chrome
login.auto=false
headless=true
db.host=openmrs
webdriver.chrome.driver=chromedriver/linux/chromedriver
includes.csrftoken=true
Expand Up @@ -6,5 +6,4 @@ webdriver=firefox
login.auto=false
headless=true
db.host=openmrs
webdriver.gecko.driver=firefoxdriver/linux/geckodriver
includes.csrftoken=true
Expand Up @@ -4,5 +4,4 @@ login.password=Admin123
login.location=Pharmacy
webdriver=chrome
headless=true
webdriver.gecko.driver=firefoxdriver/linux/geckodriver
includes.csrftoken=true
includes.csrftoken=true