Skip to content

Commit

Permalink
Fix for #130 (#132)
Browse files Browse the repository at this point in the history
* Starting AppiumEngine if not started
  • Loading branch information
RameshBabuPrudhvi authored Jun 3, 2022
1 parent b74a80c commit 9619172
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import java.net.URL;

import static io.github.selcukes.core.driver.RunMode.isCloudAppium;

@CustomLog
class AppiumEngine {
private AppiumDriverLocalService service;
Expand All @@ -39,29 +37,26 @@ public static AppiumEngine getInstance() {

URL getServiceUrl() {
if (service == null) {
throw new DriverSetupException("Appium Local server is not started...\n" +
"Please use 'GridRunner.startAppium' method to start.");
logger.debug(() -> "Appium server is not started yet. \nStarting Appium Server now...");
startLocalServer();
}
return service.getUrl();
}

void startLocalServer() {
if (!isCloudAppium()) {
try {
service = new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingAnyFreePort()
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withArgument(GeneralServerFlag.BASEPATH, "/wd/")
.build();
logger.info(() -> "Starting Appium server...");
service.start();
logger.debug(() -> String.format("Using Local ServiceUrl[%s]", service.getUrl()));
} catch (Exception e) {
throw new DriverSetupException("Failed starting Appium Server..", e);
}
try {
service = new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingAnyFreePort()
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withArgument(GeneralServerFlag.BASEPATH, "/wd/")
.build();
logger.info(() -> "Starting Appium server...");
service.start();
logger.debug(() -> String.format("Using Local ServiceUrl[%s]", service.getUrl()));
} catch (Exception e) {
throw new DriverSetupException("Failed starting Appium Server..", e);
}

}

void stopServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.selcukes.commons.config.ConfigFactory;
import io.github.selcukes.commons.exception.DriverSetupException;
import lombok.CustomLog;
import lombok.SneakyThrows;
import org.openqa.selenium.WebDriver;

import java.net.URL;
Expand All @@ -42,4 +43,10 @@ public synchronized WebDriver createDriver() {
}
return windowsDriver;
}

@SneakyThrows
@Override
public URL getServiceUrl() {
return AppiumEngine.getInstance().getServiceUrl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static <D extends WebDriver> void setDriver(D driveThread) {
DRIVER_THREAD.set(driveThread);
}

public static void removeDriver() {
public static synchronized void removeDriver() {
try {
if (getDriver() != null) {
STORED_DRIVER.remove(getDriver());
Expand All @@ -90,7 +90,7 @@ public static void removeDriver() {
}
}

public static void removeAllDrivers() {
public static synchronized void removeAllDrivers() {
logger.debug(() -> String.format("Closing [%d] stored drivers..", STORED_DRIVER.size()));
STORED_DRIVER.stream().filter(Objects::nonNull).forEach(d -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

import java.util.Arrays;

import static io.github.selcukes.core.driver.RunMode.isCloudBrowser;
import static io.github.selcukes.core.driver.RunMode.isLocalBrowser;
import static io.github.selcukes.core.driver.RunMode.*;

@CustomLog
@UtilityClass
Expand All @@ -47,14 +46,13 @@ public static synchronized void startSelenium(DriverType... driverType) {
}
}


static boolean isSeleniumServerNotRunning() {
return !isLocalBrowser() && !GridRunner.isRunning;
}

public static void startAppium() {
AppiumEngine.getInstance().startLocalServer();
}
if (!isCloudAppium())
AppiumEngine.getInstance().startLocalServer(); }

public static void stopAppium() {
AppiumEngine.getInstance().stopServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.github.selcukes.core.validation;

import io.appium.java_client.AppiumBy;
import io.github.selcukes.core.page.Page;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -43,6 +44,9 @@ public void titleContains(String expectedTitle) {
}
}

public ElementValidation element(String accessibilityId) {
return new ElementValidation(isSoft, page, page.find(AppiumBy.accessibilityId(accessibilityId)));
}
public ElementValidation element(By by) {
return new ElementValidation(isSoft, page, page.find(by));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.github.selcukes.core.tests;
package io.github.selcukes.core.tests.win;

import io.appium.java_client.windows.WindowsDriver;
import io.github.selcukes.core.driver.DriverManager;
Expand Down

0 comments on commit 9619172

Please sign in to comment.