How to use getDriverInstance method of com.testsigma.agent.services.DriverSessionsService class

Best Testsigma code snippet using com.testsigma.agent.services.DriverSessionsService.getDriverInstance

Source:DriverSessionsService.java Github

copy

Full Screen

...69 driverSessionRequest.setWebDriverServerUrl(new URL(mobileAutomationServer.getServerURL()));70 }71 webDriverSettingsDTO = fetchWebDriverSettings(driverSessionRequest);72 log.info("Creating a remote web driver session with settings - " + webDriverSettingsDTO);73 TestsigmaDriver testsigmaDriver = getDriverInstance(driverSessionRequest);74 List<WebDriverCapability> caps = webDriverSettingsDTO.getWebDriverCapabilities();75 addMissingTimeOutCapability(caps);76 handleLocalDevice(caps, driverSessionRequest);77 setRemoteServerURL(testsigmaDriver, driverSessionRequest, webDriverSettingsDTO);78 testsigmaDriver.setCapabilities(caps);79 RemoteWebDriver remoteWebDriver = testsigmaDriver.createSession();80 String sessionId = populateSessionIdMaps(remoteWebDriver, driverSessionRequest);81 sendMobileSessionStartedRequest(sessionId, driverSessionRequest);82 return sessionId;83 }84 private com.testsigma.agent.dto.WebDriverSettingsDTO fetchWebDriverSettings(DriverSessionRequest driverSessionRequest)85 throws IOException, TestsigmaException {86 HttpResponse<com.testsigma.agent.dto.WebDriverSettingsDTO> response;87 String authHeader = null;88 if (agentConfig.getJwtApiKey() == null) {89 authHeader = WebAppHttpClient.BEARER + " " + driverSessionRequest.getJwtApiKey();90 } else {91 authHeader = WebAppHttpClient.BEARER + " " + agentConfig.getJwtApiKey();92 }93 response = httpClient.post(ServerURLBuilder.webDriverSettingsURL(), driverSessionRequest, new TypeReference<>() {94 }, authHeader);95 if (response.getStatusCode() != HttpStatus.OK.value()) {96 throw new TestsigmaException("Could not fetch web driver settings from server "97 + response.getStatusCode() + " - " + response.getStatusMessage());98 }99 return response.getResponseEntity();100 }101 private String populateSessionIdMaps(RemoteWebDriver remoteWebDriver, DriverSessionRequest driverSessionRequest)102 throws Exception {103 String sessionId = remoteWebDriver.getSessionId().toString();104 if (sessionContainer.getDeviceToSessionMap().containsKey(driverSessionRequest.getUniqueId())) {105 deleteSession(sessionContainer.getDeviceToSessionMap().get(driverSessionRequest.getUniqueId()));106 }107 sessionContainer.getSessionMap().put(sessionId, remoteWebDriver);108 sessionContainer.getSessionToDeviceIdMap().put(sessionId, driverSessionRequest.getUniqueId());109 sessionContainer.getDeviceToSessionMap().put(driverSessionRequest.getUniqueId(), sessionId);110 return sessionId;111 }112 private void addMissingTimeOutCapability(List<WebDriverCapability> caps) {113 WebDriverCapability newCommandTimeoutCapability = caps.stream().filter(cap -> cap.getCapabilityName()114 .equals(TSCapabilityType.NEW_COMMAND_TIMEOUT)).findFirst().orElse(null);115 if (newCommandTimeoutCapability == null) {116 caps.add(new WebDriverCapability(TSCapabilityType.NEW_COMMAND_TIMEOUT, 0));117 }118 }119 private void setRemoteServerURL(TestsigmaDriver testsigmaDriver, DriverSessionRequest driverSessionRequest,120 WebDriverSettingsDTO webDriverSettingsDTO) throws MalformedURLException {121 if (driverSessionRequest.getExecutionLabType().equals(ExecutionLabType.Hybrid)) {122 testsigmaDriver.setRemoteServerURL(new URL(mobileAutomationServerService.getMobileAutomationServer().getServerURL()));123 } else {124 testsigmaDriver.setRemoteServerURL(webDriverSettingsDTO.getWebDriverServerUrl());125 }126 }127 private void handleLocalDevice(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)128 throws TestsigmaException, AutomatorException {129 if (driverSessionRequest.getExecutionLabType().equals(ExecutionLabType.Hybrid)) {130 appendChromeDriverExecutable(caps, driverSessionRequest);131 if (driverSessionRequest.getWorkspaceType() == WorkspaceType.IOSNative) {132 setupIosDevice(caps, driverSessionRequest);133 }134 }135 }136 private void appendChromeDriverExecutable(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)137 throws TestsigmaException {138 MobileDevice device = deviceContainer.getDevice(driverSessionRequest.getUniqueId());139 if (device.getBrowserList() != null && device.getBrowserList().size() > 0) {140 AgentBrowser browser = device.getBrowserList().get(0);141 File chromePath = driverExecutableExists(Browsers.GoogleChrome.getKey(),142 browser.getMajorVersion() + "");143 if (chromePath != null) {144 WebDriverCapability cap = new WebDriverCapability(TSCapabilityType.CHROME_DRIVER_EXECUTABLE, chromePath.getAbsolutePath());145 caps.add(cap);146 } else {147 log.warn("Chrome Driver is not yet downloaded.. please try after some time");148 }149 }150 }151 public void setupIosDevice(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)152 throws TestsigmaException, AutomatorException {153 MobileDevice device = deviceContainer.getDevice(driverSessionRequest.getUniqueId());154 iosDeviceService.setupWda(device);155 WebDriverCapability bundleIdCapability = caps.stream().filter(cap -> cap.getCapabilityName()156 .equals(TSCapabilityType.BUNDLE_ID)).findFirst().orElse(null);157 if ((bundleIdCapability == null) || StringUtils.isBlank((String) bundleIdCapability.getCapabilityValue())) {158 WebDriverCapability appCapability = caps.stream().filter(cap -> cap.getCapabilityName()159 .equals(MobileCapabilityType.APP)).findFirst().orElse(null);160 AppPathType appPathType = driverSessionRequest.getApplicationPathType();161 if ((appCapability != null) && appPathType != AppPathType.APP_DETAILS) {162 caps.remove(appCapability);163 String appPresignedUrl = (String) appCapability.getCapabilityValue();164 String bundleId = iosDeviceService.installApp(device, appPresignedUrl, device.getIsEmulator());165 caps.add(new WebDriverCapability(TSCapabilityType.BUNDLE_ID, bundleId));166 }167 }168 }169 private TestsigmaDriver getDriverInstance(DriverSessionRequest driverSessionRequest) {170 TestsigmaDriver testsigmaDriver = new TestsigmaDriver();171 if (Platform.Android.equals(driverSessionRequest.getPlatform())) {172 testsigmaDriver = new AndroidDriver();173 } else if (Platform.iOS.equals(driverSessionRequest.getPlatform())) {174 testsigmaDriver = new IosDriver();175 }176 return testsigmaDriver;177 }178 public void deleteSession(String sessionId) throws Exception {179 log.debug("Removing session from appium server");180 RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);181 new TestsigmaDriver().deleteSession(remoteWebDriver);182 if (sessionContainer.getSessionMap().containsKey(sessionId)) {183 sessionContainer.getSessionMap().remove(sessionId);...

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