How to use SeLionSauceProxy class of com.paypal.selion.proxy package

Best SeLion code snippet using com.paypal.selion.proxy.SeLionSauceProxy

Source:SauceServlet.java Github

copy

Full Screen

...21import javax.servlet.http.HttpServletRequest;22import javax.servlet.http.HttpServletResponse;23import com.paypal.selion.logging.SeLionGridLogger;24import com.paypal.selion.pojos.SeLionGridConstants;25import com.paypal.selion.proxy.SeLionSauceProxy;26import com.paypal.selion.utils.SauceLabsRestApi;27import org.apache.commons.lang.StringUtils;28import org.apache.http.HttpHost;29import org.apache.http.HttpResponse;30import org.apache.http.client.HttpClient;31import org.apache.http.entity.StringEntity;32import org.apache.http.message.BasicHttpEntityEnclosingRequest;33import org.openqa.grid.common.RegistrationRequest;34import org.openqa.grid.common.exception.GridConfigurationException;35import org.openqa.grid.internal.GridRegistry;36import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;37import org.openqa.grid.web.servlet.RegistryBasedServlet;38import org.openqa.selenium.MutableCapabilities;39import org.openqa.selenium.remote.internal.HttpClientFactory;40import com.paypal.selion.utils.ServletHelper;41/**42 * This {@link RegistryBasedServlet} based servlet takes care of spinning up or tearing down a virtual sauce node.<br>43 * <br>44 * This servlet requires the hub to also have {@link LoginServlet} available.45 */46public class SauceServlet extends RegistryBasedServlet {47 private static final SeLionGridLogger LOGGER = SeLionGridLogger.getLogger(SauceServlet.class);48 private static final long serialVersionUID = 9187677490975386050L;49 private static final String MAX_INSTANCES_CONFIG_PROPERTY = "maxInstances";50 private static final String SAUCELABS_BROWSER_NAME = "saucelabs";51 private static final String PROXY_HOST = "ondemand.saucelabs.com";52 private static final int PROXY_PORT = 80;53 /**54 * The proxy id that will be used to register to the hub55 */56 public static final String PROXY_ID = "http://" + PROXY_HOST + ":" + PROXY_PORT;57 /**58 * Request parameter that trigger a proxy shutdown action59 */60 public static final String SHUTDOWN_PARAM = "shutdown";61 private boolean registered;62 public SauceServlet(GridRegistry registry) {63 super(registry);64 }65 public SauceServlet() {66 this(null);67 }68 private String formatForHtmlTemplate(String message) {69 return String.format("<p align='center'><b>%s</b></p>", message);70 }71 @Override72 protected GridRegistry getRegistry() {73 // ensure the Registry returned reflects the hub state.74 final GridRegistry localRegistry = super.getRegistry();75 final GridRegistry hubRegistry = localRegistry.getHub().getRegistry();76 // yes, we only care if they are the same object reference.77 return (localRegistry.equals(hubRegistry)) ? localRegistry : hubRegistry;78 }79 /*80 * Disconnects the virtual node from the hub81 */82 private synchronized void disconnectVirtualSauceNodeFromGrid(HttpServletRequest req, HttpServletResponse resp)83 throws IOException {84 // Redirecting to login page if session is not found85 if (req.getSession(false) == null) {86 resp.sendRedirect(LoginServlet.class.getSimpleName());87 return;88 }89 String msg = "There is no sauce node running.";90 final SeLionSauceProxy proxy = (SeLionSauceProxy) getRegistry().getProxyById(PROXY_ID);91 if (proxy != null) {92 proxy.teardown();93 getRegistry().removeIfPresent(proxy);94 msg = "Sauce node shutdown successfully.";95 }96 registered = false;97 LOGGER.info(msg);98 ServletHelper.respondAsHtmlWithMessage(resp, formatForHtmlTemplate(msg));99 }100 /*101 * A helper method that takes care of registering a virtual node to the hub.102 */103 private synchronized void registerVirtualSauceNodeToGrid(HttpServletRequest req, HttpServletResponse resp)104 throws ServletException, IOException {105 // Redirecting to login page if session is not found106 if (req.getSession(false) == null) {107 resp.sendRedirect(LoginServlet.class.getSimpleName());108 return;109 }110 String respMsg = "Sauce node already registered.";111 if (registered) {112 ServletHelper.respondAsHtmlWithMessage(resp, formatForHtmlTemplate(respMsg));113 LOGGER.info(respMsg);114 return;115 }116 HttpClientFactory httpClientFactory = new HttpClientFactory();117 respMsg = "Sauce node registration failed. Please refer to the log file for failure details.";118 try {119 final int port = getRegistry().getHub().getConfiguration().port;120 final URL registration = new URL("http://localhost:" + port + "/grid/register");121 BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",122 registration.toExternalForm());123 request.setEntity(new StringEntity(getRegistrationRequestEntity()));124 HttpHost host = new HttpHost(registration.getHost(), registration.getPort());125 HttpClient client = httpClientFactory.getHttpClient();126 HttpResponse response = client.execute(host, request);127 if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) {128 respMsg = "Sauce node registered successfully.";129 registered = true;130 }131 } catch (IOException | GridConfigurationException e) { // We catch the GridConfigurationException here to fail132 // gracefully133 // TODO Consider retrying on failure134 LOGGER.log(Level.WARNING, "Unable to register sauce node: ", e);135 } finally {136 httpClientFactory.close();137 }138 LOGGER.info(respMsg);139 ServletHelper.respondAsHtmlWithMessage(resp, formatForHtmlTemplate(respMsg));140 }141 /*142 * Update the registration request entity143 */144 private String getRegistrationRequestEntity() throws FileNotFoundException {145 // update the registration request with the max concurrent sessions/vms146 final GridNodeConfiguration gnc =147 GridNodeConfiguration.loadFromJSON(SeLionGridConstants.NODE_SAUCE_CONFIG_FILE);148 // get the max concurrent vm's allowed for the account from sauce labs149 final SauceLabsRestApi restApi;150 try {151 restApi = new SauceLabsRestApi();152 } catch (GridConfigurationException e) {153 throw e;154 }155 final int maxConcurrent = restApi.getMaxConcurrency();156 if (maxConcurrent != -1) {157 // update max sessions158 gnc.maxSession = maxConcurrent;159 // update browser max instances for all saucelabs "browser" types160 for (MutableCapabilities caps : gnc.capabilities) {161 if (caps.getBrowserName().equals(SAUCELABS_BROWSER_NAME)) {162 caps.setCapability(MAX_INSTANCES_CONFIG_PROPERTY, maxConcurrent);163 }164 }165 }166 // ensure the proxy host, port, id is set for http://ondemand.saucelabs.com:80167 if (StringUtils.isBlank(gnc.host)) {168 gnc.host = PROXY_HOST;169 }170 if (StringUtils.isBlank(gnc.id)) {171 gnc.id = PROXY_ID;172 }173 if (gnc.port == null || gnc.port < 0) {174 gnc.port = PROXY_PORT;175 }176 return new RegistrationRequest(gnc, SeLionSauceProxy.class.getSimpleName(),177 "SeLion Grid Virtual Sauce Proxy").toJson().toString();178 }179 @Override180 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {181 if (request.getParameter(SHUTDOWN_PARAM) != null) {182 disconnectVirtualSauceNodeFromGrid(request, response);183 return;184 }185 registerVirtualSauceNodeToGrid(request, response);186 }187 @Override188 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,189 IOException {190 if (request.getParameter(SHUTDOWN_PARAM) != null) {...

Full Screen

Full Screen

Source:SeLionSauceCapabilityMatcher.java Github

copy

Full Screen

...14\*-------------------------------------------------------------------------------------------------------------------*/15package com.paypal.selion.grid.matchers;16import java.util.Map;17import org.openqa.grid.internal.utils.CapabilityMatcher;18import com.paypal.selion.proxy.SeLionSauceProxy;19/**20 * Used in conjunction with a grid that has a {@link SeLionSauceProxy} connected. <br>21 * <br>22 * A simple {@link CapabilityMatcher} which delegates matches against node capabilities to the Sauce Labs cloud when23 * {@link SeLionSauceProxy} forwards the session.24 * 25 */26public class SeLionSauceCapabilityMatcher implements CapabilityMatcher {27 public boolean matches(Map<String, Object> nodeCapability, Map<String, Object> requestedCapabilities) {28 // nothing to check.. delegate everything to sauce labs cloud29 return true;30 }31}

Full Screen

Full Screen

SeLionSauceProxy

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.proxy.SeLionSauceProxy;2public class 3 {3 public static void main(String[] args) throws Exception {4 SeLionSauceProxy proxy = new SeLionSauceProxy();5 proxy.start();6 proxy.stop();7 }8}9import com.paypal.selion.proxy.SeLionSauceProxy;10public class 4 {11 public static void main(String[] args) throws Exception {12 SeLionSauceProxy proxy = new SeLionSauceProxy();13 proxy.start();14 proxy.stop();15 }16}17import com.paypal.selion.proxy.SeLionSauceProxy;18public class 5 {19 public static void main(String[] args) throws Exception {20 SeLionSauceProxy proxy = new SeLionSauceProxy();21 proxy.start();22 proxy.stop();23 }24}25import com.paypal.selion.proxy.SeLionSauceProxy;26public class 6 {27 public static void main(String[] args) throws Exception {28 SeLionSauceProxy proxy = new SeLionSauceProxy();29 proxy.start();30 proxy.stop();31 }32}33import com.paypal.selion.proxy.SeLionSauceProxy;34public class 7 {35 public static void main(String[] args) throws Exception {36 SeLionSauceProxy proxy = new SeLionSauceProxy();37 proxy.start();38 proxy.stop();39 }40}41import com.paypal.selion.proxy.SeLionSauceProxy;42public class 8 {43 public static void main(String[] args) throws Exception {44 SeLionSauceProxy proxy = new SeLionSauceProxy();45 proxy.start();46 proxy.stop();47 }48}

Full Screen

Full Screen

SeLionSauceProxy

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.proxy;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.remote.DesiredCapabilities;5import com.paypal.selion.annotations.WebTest;6import com.paypal.selion.platform.grid.Grid;7import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;8import com.paypal.selion.platform.grid.browsercapabilities.SeLionCapabilityHelper;9import com.paypal.selion.platform.grid.browsercapabilities.SeLionSauceProxy;10import com.paypal.selion.platform.grid.browsercapabilities.SeLionSauceProxy.SauceOptions;11import com.paypal.selion.platform.grid.browsercapabilities.SeLionSauceProxy.SauceOptions.SauceOptionsBuilder;12import com.paypal.selion.platform.grid.browsercapabilities.SeLionSauceProxy.SauceOptions.SauceOptionsBuilder.SauceOptionsVersion;13import com.paypal.selion.platform.utilities.WebDriverWaitUtils;14public class SeLionSauceProxyTest {15 public void testSauceProxy() throws MalformedURLException {16 DesiredCapabilities capabilities = DefaultCapabilitiesBuilder.getInstance().getCapabilities(DesiredCapabilities.firefox());17 SauceOptions sauceOptions = SauceOptionsBuilder.builder().withBuild("test build").withVersion(SauceOptionsVersion.V4).build();18 SeLionSauceProxy sauceProxy = new SeLionSauceProxy(sauceOptions);19 capabilities.setCapability(SeLionCapabilityHelper.SAUCE_PROXY, sauceProxy);20 WebDriverWaitUtils.waitUntilElementIsPresent("q").sendKeys("sauce labs");21 }22}

Full Screen

Full Screen

SeLionSauceProxy

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.proxy.SeLionSauceProxy;2public class SauceProxy {3 public static void main(String[] args) {4 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();5 sauceProxy.startProxy();6 sauceProxy.stopProxy();7 }8}9import com.paypal.selion.proxy.SeLionSauceProxy;10public class SauceProxy {11 public static void main(String[] args) {12 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();13 sauceProxy.startProxy();14 sauceProxy.stopProxy();15 }16}17import com.paypal.selion.proxy.SeLionSauceProxy;18public class SauceProxy {19 public static void main(String[] args) {20 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();21 sauceProxy.startProxy();22 sauceProxy.stopProxy();23 }24}25import com.paypal.selion.proxy.SeLionSauceProxy;26public class SauceProxy {27 public static void main(String[] args) {28 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();29 sauceProxy.startProxy();30 sauceProxy.stopProxy();31 }32}33import com.paypal.selion.proxy.SeLionSauceProxy;34public class SauceProxy {35 public static void main(String[] args) {36 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();37 sauceProxy.startProxy();38 sauceProxy.stopProxy();39 }40}

Full Screen

Full Screen

SeLionSauceProxy

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.sauce;2import java.net.URL;3import java.util.logging.Level;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.openqa.selenium.remote.RemoteWebDriver;7import com.paypal.selion.configuration.Config;8import com.paypal.selion.configuration.Config.ConfigProperty;9import com.paypal.selion.logger.SeLionGridLogger;10import com.paypal.selion.proxy.SeLionSauceProxy;11public class SauceTest {12 private static final SeLionGridLogger logger = SeLionGridLogger.getLogger(SauceTest.class);13 public static void main(String[] args) throws Exception {14 Config config = Config.getConfig();15 String sauceUserName = config.getStringConfigProperty(ConfigProperty.SELENIUM_SAUCELABS_USER_NAME);16 String sauceAccessKey = config.getStringConfigProperty(ConfigProperty.SELENIUM_SAUCELABS_ACCESS_KEY);17 String sauceURL = config.getStringConfigProperty(ConfigProperty.SELENIUM_SAUCELABS_URL);18 DesiredCapabilities capabilities = new DesiredCapabilities();19 capabilities.setCapability("browserName", "firefox");20 capabilities.setCapability("version", "34");21 capabilities.setCapability("platform", "Windows 8.1");22 capabilities.setCapability("name", "SeLion Sauce Test");23 WebDriver driver = null;24 try {25 SeLionSauceProxy sauceProxy = new SeLionSauceProxy(new URL(sauceURL), sauceUserName, sauceAccessKey);26 driver = new RemoteWebDriver(sauceProxy, capabilities);27 System.out.println("Page title is: " + driver.getTitle());28 } catch (Exception e) {29 logger.log(Level.SEVERE, e.getMessage(), e);30 } finally {31 if (driver != null) {32 driver.quit();33 }34 }35 }36}37package com.paypal.selion.sauce;38import java.net.URL;39import java.util.logging.Level;40import org.openqa.selenium.WebDriver;41import org.openqa.selenium.remote.DesiredCapabilities;42import org.openqa.selenium.remote.RemoteWebDriver;43import com.paypal.selion.configuration.Config;44import com.paypal.selion.configuration.Config.ConfigProperty;45import com.paypal.selion.logger.SeLionGridLogger;46import com.paypal.selion.proxy.SeLionSauceProxy;

Full Screen

Full Screen

SeLionSauceProxy

Using AI Code Generation

copy

Full Screen

1public class TestSauceConnect {2 public static void main(String[] args) {3 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();4 sauceProxy.startSauceConnect();5 }6}7public class TestSauceConnect {8 public static void main(String[] args) {9 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();10 sauceProxy.stopSauceConnect();11 }12}13public class TestSauceConnect {14 public static void main(String[] args) {15 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();16 sauceProxy.isSauceConnectRunning();17 }18}19public class TestSauceConnect {20 public static void main(String[] args) {21 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();22 sauceProxy.isSauceConnectRunning();23 }24}25public class TestSauceConnect {26 public static void main(String[] args) {27 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();28 sauceProxy.isSauceConnectRunning();29 }30}31public class TestSauceConnect {32 public static void main(String[] args) {33 SeLionSauceProxy sauceProxy = new SeLionSauceProxy();34 sauceProxy.isSauceConnectRunning();35 }36}

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