How to use TestsigmaDriver class of com.testsigma.automator.drivers package

Best Testsigma code snippet using com.testsigma.automator.drivers.TestsigmaDriver

Source:DriverSessionsService.java Github

copy

Full Screen

...20import com.testsigma.agent.request.MobileInspectionRequest;21import com.fasterxml.jackson.core.type.TypeReference;22import com.testsigma.automator.AutomatorConfig;23import com.testsigma.automator.constants.TSCapabilityType;24import com.testsigma.automator.drivers.TestsigmaDriver;25import com.testsigma.automator.drivers.WebDriverCapability;26import com.testsigma.automator.drivers.mobile.AndroidDriver;27import com.testsigma.automator.drivers.mobile.IosDriver;28import com.testsigma.automator.entity.*;29import com.testsigma.automator.exceptions.AutomatorException;30import com.testsigma.automator.http.HttpResponse;31import com.testsigma.automator.utilities.PathUtil;32import io.appium.java_client.remote.MobileCapabilityType;33import lombok.Data;34import lombok.RequiredArgsConstructor;35import lombok.extern.log4j.Log4j2;36import org.apache.commons.lang3.StringUtils;37import org.openqa.selenium.remote.Command;38import org.openqa.selenium.remote.RemoteWebDriver;39import org.openqa.selenium.remote.Response;40import org.openqa.selenium.remote.SessionId;41import org.springframework.beans.factory.annotation.Autowired;42import org.springframework.http.HttpStatus;43import org.springframework.stereotype.Service;44import java.io.File;45import java.io.IOException;46import java.net.MalformedURLException;47import java.net.URL;48import java.nio.file.Paths;49import java.sql.Timestamp;50import java.util.List;51@Data52@Log4j253@Service54@RequiredArgsConstructor(onConstructor = @__(@Autowired))55public class DriverSessionsService {56 private final SessionContainer sessionContainer;57 private final DeviceContainer deviceContainer;58 private final WebAppHttpClient httpClient;59 private final MobileAutomationServer mobileAutomationServer;60 private final AgentConfig agentConfig;61 private final IosDeviceService iosDeviceService;62 private final MobileAutomationServerService mobileAutomationServerService;63 public String createSession(DriverSessionRequest driverSessionRequest) throws Exception {64 com.testsigma.agent.dto.WebDriverSettingsDTO webDriverSettingsDTO;65 if (ExecutionLabType.Hybrid.equals(driverSessionRequest.getExecutionLabType())66 && WorkspaceType.isMobileApp(driverSessionRequest.getWorkspaceType())) {67 disconnectDeviceSession(driverSessionRequest.getUniqueId());68 driverSessionRequest.setWebDriverServerUrl(new URL(mobileAutomationServer.getServerURL()));69 }70 webDriverSettingsDTO = fetchWebDriverSettings(driverSessionRequest);71 log.info("Creating a remote web driver session with settings - " + webDriverSettingsDTO);72 TestsigmaDriver testsigmaDriver = getDriverInstance(driverSessionRequest);73 List<WebDriverCapability> caps = webDriverSettingsDTO.getWebDriverCapabilities();74 addMissingTimeOutCapability(caps);75 handleLocalDevice(caps, driverSessionRequest);76 setRemoteServerURL(testsigmaDriver, driverSessionRequest, webDriverSettingsDTO);77 testsigmaDriver.setCapabilities(caps);78 RemoteWebDriver remoteWebDriver = testsigmaDriver.createSession();79 String sessionId = populateSessionIdMaps(remoteWebDriver, driverSessionRequest);80 sendMobileSessionStartedRequest(sessionId, driverSessionRequest);81 return sessionId;82 }83 private com.testsigma.agent.dto.WebDriverSettingsDTO fetchWebDriverSettings(DriverSessionRequest driverSessionRequest)84 throws IOException, TestsigmaException {85 HttpResponse<com.testsigma.agent.dto.WebDriverSettingsDTO> response;86 String authHeader = null;87 if (agentConfig.getJwtApiKey() == null) {88 authHeader = WebAppHttpClient.BEARER + " " + driverSessionRequest.getJwtApiKey();89 } else {90 authHeader = WebAppHttpClient.BEARER + " " + agentConfig.getJwtApiKey();91 }92 response = httpClient.post(ServerURLBuilder.webDriverSettingsURL(), driverSessionRequest, new TypeReference<>() {93 }, authHeader);94 if (response.getStatusCode() != HttpStatus.OK.value()) {95 throw new TestsigmaException("Could not fetch web driver settings from server "96 + response.getStatusCode() + " - " + response.getStatusMessage());97 }98 return response.getResponseEntity();99 }100 private String populateSessionIdMaps(RemoteWebDriver remoteWebDriver, DriverSessionRequest driverSessionRequest)101 throws Exception {102 String sessionId = remoteWebDriver.getSessionId().toString();103 if (sessionContainer.getDeviceToSessionMap().containsKey(driverSessionRequest.getUniqueId())) {104 deleteSession(sessionContainer.getDeviceToSessionMap().get(driverSessionRequest.getUniqueId()));105 }106 sessionContainer.getSessionMap().put(sessionId, remoteWebDriver);107 sessionContainer.getSessionToDeviceIdMap().put(sessionId, driverSessionRequest.getUniqueId());108 sessionContainer.getDeviceToSessionMap().put(driverSessionRequest.getUniqueId(), sessionId);109 return sessionId;110 }111 private void addMissingTimeOutCapability(List<WebDriverCapability> caps) {112 WebDriverCapability newCommandTimeoutCapability = caps.stream().filter(cap -> cap.getCapabilityName()113 .equals(TSCapabilityType.NEW_COMMAND_TIMEOUT)).findFirst().orElse(null);114 if (newCommandTimeoutCapability == null) {115 caps.add(new WebDriverCapability(TSCapabilityType.NEW_COMMAND_TIMEOUT, 0));116 }117 }118 private void setRemoteServerURL(TestsigmaDriver testsigmaDriver, DriverSessionRequest driverSessionRequest,119 WebDriverSettingsDTO webDriverSettingsDTO) throws MalformedURLException {120 if (driverSessionRequest.getExecutionLabType().equals(ExecutionLabType.Hybrid)) {121 testsigmaDriver.setRemoteServerURL(new URL(mobileAutomationServerService.getMobileAutomationServer().getServerURL()));122 } else {123 testsigmaDriver.setRemoteServerURL(webDriverSettingsDTO.getWebDriverServerUrl());124 }125 }126 private void handleLocalDevice(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)127 throws TestsigmaException, AutomatorException {128 if (driverSessionRequest.getExecutionLabType().equals(ExecutionLabType.Hybrid)) {129 appendChromeDriverExecutable(caps, driverSessionRequest);130 if (driverSessionRequest.getWorkspaceType() == WorkspaceType.IOSNative) {131 setupIosDevice(caps, driverSessionRequest);132 }133 }134 }135 private void appendChromeDriverExecutable(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)136 throws TestsigmaException {137 MobileDevice device = deviceContainer.getDevice(driverSessionRequest.getUniqueId());138 if (device.getBrowserList() != null && device.getBrowserList().size() > 0) {139 AgentBrowser browser = device.getBrowserList().get(0);140 File chromePath = driverExecutableExists(Browsers.GoogleChrome.getKey(),141 browser.getMajorVersion() + "");142 if (chromePath != null) {143 WebDriverCapability cap = new WebDriverCapability(TSCapabilityType.CHROME_DRIVER_EXECUTABLE, chromePath.getAbsolutePath());144 caps.add(cap);145 } else {146 log.warn("Chrome Driver is not yet downloaded.. please try after some time");147 }148 }149 }150 public void setupIosDevice(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)151 throws TestsigmaException, AutomatorException {152 MobileDevice device = deviceContainer.getDevice(driverSessionRequest.getUniqueId());153 iosDeviceService.setupWda(device);154 WebDriverCapability bundleIdCapability = caps.stream().filter(cap -> cap.getCapabilityName()155 .equals(TSCapabilityType.BUNDLE_ID)).findFirst().orElse(null);156 if ((bundleIdCapability == null) || StringUtils.isBlank((String) bundleIdCapability.getCapabilityValue())) {157 WebDriverCapability appCapability = caps.stream().filter(cap -> cap.getCapabilityName()158 .equals(MobileCapabilityType.APP)).findFirst().orElse(null);159 AppPathType appPathType = driverSessionRequest.getApplicationPathType();160 if ((appCapability != null) && appPathType != AppPathType.APP_DETAILS) {161 caps.remove(appCapability);162 String appPresignedUrl = (String) appCapability.getCapabilityValue();163 String bundleId = iosDeviceService.installApp(device, appPresignedUrl);164 caps.add(new WebDriverCapability(TSCapabilityType.BUNDLE_ID, bundleId));165 }166 }167 }168 private TestsigmaDriver getDriverInstance(DriverSessionRequest driverSessionRequest) {169 TestsigmaDriver testsigmaDriver = new TestsigmaDriver();170 if (Platform.Android.equals(driverSessionRequest.getPlatform())) {171 testsigmaDriver = new AndroidDriver();172 } else if (Platform.iOS.equals(driverSessionRequest.getPlatform())) {173 testsigmaDriver = new IosDriver();174 }175 return testsigmaDriver;176 }177 public void deleteSession(String sessionId) throws Exception {178 log.debug("Removing session from appium server");179 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);180 new TestsigmaDriver().deleteSession(remoteWebDriver);181 if (sessionContainer.getSessionMap().containsKey(sessionId)) {182 sessionContainer.getSessionMap().remove(sessionId);183 String deviceId = sessionContainer.getSessionToDeviceIdMap().get(sessionId);184 sessionContainer.getSessionToDeviceIdMap().remove(sessionId);185 sessionContainer.getDeviceToSessionMap().remove(deviceId);186 if (deviceContainer != null && deviceContainer.getDeviceMap().containsKey(deviceId)) {187 MobileDevice device = deviceContainer.getDevice(deviceId);188 if((device != null) && (device.getOsName() == MobileOs.IOS)) {189 iosDeviceService.cleanupWda(device);190 } else {191 log.info("Device os is not iOS. Skipping WDA cleanup");192 }193 }194 } else {...

Full Screen

Full Screen

Source:MobileDriver.java Github

copy

Full Screen

1package com.testsigma.automator.drivers.mobile;2import com.testsigma.automator.constants.TSCapabilityType;3import com.testsigma.automator.drivers.TestsigmaDriver;4import com.testsigma.automator.drivers.WebDriverCapability;5import com.testsigma.automator.entity.AppPathType;6import com.testsigma.automator.entity.WorkspaceType;7import com.testsigma.automator.exceptions.AutomatorException;8import com.testsigma.automator.mobile.ios.AppInstaller;9import com.testsigma.automator.runners.EnvironmentRunner;10import lombok.Data;11import lombok.EqualsAndHashCode;12import lombok.extern.log4j.Log4j2;13import org.apache.commons.lang3.StringUtils;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.remote.RemoteWebDriver;16import javax.net.ssl.SSLException;17import java.net.ConnectException;18import java.net.MalformedURLException;19import java.util.Calendar;20import java.util.List;21@EqualsAndHashCode(callSuper = true)22@Data23@Log4j224public class MobileDriver extends TestsigmaDriver {25 public static final String APPIUM_INVALID_URL = "<br> For more information - <a href = \"https://support.testsigma.com/a/solutions/articles/32000023959-most-common-errors-appium-specific\" target=\"_blank\">https://support.testsigma.com/a/solutions/articles/32000023959-most-common-errors-appium-specific</a>";26 public MobileDriver() {27 super();28 }29 @Override30 protected void setCapabilities() throws AutomatorException, MalformedURLException {31 super.setCapabilities();32 List<WebDriverCapability> additionalCapabilitiesList = webDriverSettings.getWebDriverCapabilities();33 setCommonCapabilities();34 setPlatformSpecificCapabilities();35 setAdditionalCapabilities(additionalCapabilitiesList);36 }37 @Override38 protected void setCommonCapabilities() throws AutomatorException {...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful