Best SeLion code snippet using com.paypal.selion.platform.grid.RemoteNodeInformation
Source:Grid.java
...172 * An object of type {@link SessionId} which represents the current session for a user.173 * @return An array of string wherein the first element represents the remote node's name and the second element174 * represents its port. May return <code>null</code> on error.175 */176 public static RemoteNodeInformation getRemoteNodeInfo(String hostName, int port, SessionId session) {177 logger.entering(new Object[] { hostName, port, session });178 RemoteNodeInformation node = null;179 String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: ";180 // go ahead and abort if this is a known grid where know we won't be able to extract the proxy info via the hub181 // api182 if (Config.getBoolConfigProperty(ConfigProperty.SELENIUM_USE_SAUCELAB_GRID)) {183 logger.exiting(node);184 return node;185 }186 try {187 HttpHost host = new HttpHost(hostName, port);188 CloseableHttpClient client = HttpClientBuilder.create().build();189 URL sessionURL = new URL("http://" + hostName + ":" + port + "/grid/api/testsession?session=" + session);190 BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());191 CloseableHttpResponse response = client.execute(host, r);192 JSONObject object = extractObject(response);193 URL myURL = new URL(object.getString("proxyId"));194 if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {195 node = new RemoteNodeInformation(myURL.getHost(), myURL.getPort());196 }197 } catch (Exception e) {198 logger.log(Level.FINE, errorMsg, e);199 // Just log the exception at finer level but dont throw any exceptions200 // because this is just value added information.201 }202 logger.exiting(node);203 return node;204 }205}...
Source:WebTestSession.java
...22import com.paypal.selion.internal.platform.grid.browsercapabilities.WebDriverFactory;23import com.paypal.selion.internal.utils.InvokedMethodInformation;24import com.paypal.selion.logger.SeLionLogger;25import com.paypal.selion.platform.grid.Grid;26import com.paypal.selion.platform.grid.RemoteNodeInformation;27import com.paypal.test.utilities.logging.SimpleLogger;28/**29 * A class for loading and representing the {@link WebTest} annotation parameters. Also performs sanity checks.30 */31public class WebTestSession extends AbstractTestSession {32 private String browser = "";33 private int browserHeight;34 private int browserWidth;35 private static final SimpleLogger logger = SeLionLogger.getLogger();36 WebTestSession() {37 super();38 }39 /**40 * Call this to initialize the {@link WebTestSession} object from the TestNG {@link IInvokedMethod}41 *42 * @param method43 * - the TestNG {@link IInvokedMethod}44 *45 */46 @Override47 public void initializeTestSession(InvokedMethodInformation method) {48 this.initTestSession(method);49 WebTest webTestAnnotation = method.getAnnotation(WebTest.class);50 // check class has webtest annotation (i.e. using shared sessions)51 if (webTestAnnotation == null) {52 webTestAnnotation = method.getActualMethod().getDeclaringClass().getAnnotation(WebTest.class);53 }54 // Setting the browser value55 this.browser = getLocalConfigProperty(ConfigProperty.BROWSER);56 if (webTestAnnotation != null) {57 if (StringUtils.isNotBlank(webTestAnnotation.browser())) {58 this.browser = webTestAnnotation.browser();59 }60 if (webTestAnnotation.browserHeight() > 0 && webTestAnnotation.browserWidth() > 0) {61 this.browserHeight = webTestAnnotation.browserHeight();62 this.browserWidth = webTestAnnotation.browserWidth();63 } else {64 warnUserOfInvalidBrowserDimensions(webTestAnnotation);65 }66 initializeAdditionalCapabilities(method);67 initializeAdditionalCapabilities(webTestAnnotation.additionalCapabilities());68 initializeAdditionalCapabilities(webTestAnnotation.additionalCapabilitiesBuilders());69 }70 }71 private void warnUserOfInvalidBrowserDimensions(WebTest webTestAnnotation) {72 if (webTestAnnotation.browserHeight() < 0 && webTestAnnotation.browserWidth() < 0) {73 logger.info("The parameters provided in WebTest annotation are less than zero. Ignoring them.");74 }75 if (webTestAnnotation.browserHeight() == 0 && webTestAnnotation.browserWidth() == 0) {76 logger.fine("No parameters for browser dimensions were provided.");77 } else if (webTestAnnotation.browserHeight() == 0) {78 logger.info("The height was not provided ignoring width parameter.");79 } else if (webTestAnnotation.browserWidth() == 0) {80 logger.info("The width was not provided ignoring height parameter.");81 }82 }83 /**84 * @return the browser configured for the test method85 */86 public final String getBrowser() {87 logger.entering();88 // By now we would have already set the browser flavor from the local config as part of the89 // initializeTestSession90 // method. So lets check if its still blank and if yes, we default it to the global config value.91 if (StringUtils.isBlank(this.browser)) {92 this.browser = Config.getConfigProperty(ConfigProperty.BROWSER);93 }94 // All of our browser values need to start with the magic char "*"95 if (!StringUtils.startsWith(this.browser, "*")) {96 this.browser = "*".concat(this.browser);97 }98 logger.exiting(this.browser);99 return this.browser;100 }101 /**102 * @return the height of the Browser window that will be spawned103 */104 public final int getBrowserHeight() {105 if (this.browserHeight == 0 || this.browserWidth == 0) {106 String height = getLocalConfigProperty(ConfigProperty.BROWSER_HEIGHT);107 if (StringUtils.isNotBlank(height)) {108 this.browserHeight = Integer.parseInt(height);109 }110 }111 return (this.browserHeight);112 }113 /**114 * @return the width of the browser window that will be spawned115 */116 public final int getBrowserWidth() {117 if (this.browserHeight == 0 || this.browserWidth == 0) {118 String width = getLocalConfigProperty(ConfigProperty.BROWSER_WIDTH);119 if (StringUtils.isNotBlank(width)) {120 this.browserWidth = Integer.parseInt(width);121 }122 }123 return (this.browserWidth);124 }125 private boolean runLocally() {126 return Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.SELENIUM_RUN_LOCALLY));127 }128 private void createSession() {129 logger.entering();130 BrowserFlavors flavor = BrowserFlavors.getBrowser(getBrowser());131 RemoteWebDriver driver = WebDriverFactory.createInstance(flavor);132 if (!runLocally()) {133 String hostName = Config.getConfigProperty(ConfigProperty.SELENIUM_HOST);134 int port = Integer.parseInt(Config.getConfigProperty(ConfigProperty.SELENIUM_PORT));135 RemoteNodeInformation node = Grid.getRemoteNodeInfo(hostName, port, driver.getSessionId());136 if (node != null) {137 logger.info(node.toString());138 }139 }140 Grid.getThreadLocalWebDriver().set(driver);141 logger.exiting();142 }143 @Override144 public void startSession() {145 createSession();146 setStarted(true);147 }148 @Override149 public WebDriverPlatform getPlatform() {...
RemoteNodeInformation
Using AI Code Generation
1package com.paypal.selion.platform.grid;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.logging.Level;5import java.util.logging.Logger;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.remote.RemoteWebDriver;8import org.testng.annotations.Test;9public class RemoteNodeInformationTest {10public void testGetRemoteNodeInformation() {11 DesiredCapabilities capabilities = DesiredCapabilities.firefox();12 capabilities.setCapability("platform", "WINDOWS");13 capabilities.setCapability("browserName", "firefox");14 capabilities.setCapability("version", "3.6");15 RemoteWebDriver driver = null;16 try {17 } catch (MalformedURLException ex) {18 Logger.getLogger(RemoteNodeInformationTest.class.getName()).log(Level.SEVERE, null, ex);19 }20 RemoteNodeInformation node = new RemoteNodeInformation(driver);21 System.out.println(node.toString());22 System.out.println(node.getHostName());23 System.out.println(node.getIpAddress());24 System.out.println(node.getPort());25 System.out.println(node.getVersion());26 System.out.println(node.getMaxSession());27 System.out.println(node.getCurrentSession());28 System.out.println(node.getOs());29 System.out.println(node.getOsArch());30 System.out.println(node.getOsVersion());31 System.out.println(node.getAvailableProcessors());32 System.out.println(node.getTotalMemory());33 System.out.println(node.getFreeMemory());34 System.out.println(node.getMaxMemory());35 driver.quit();36}37}
RemoteNodeInformation
Using AI Code Generation
1package com.paypal.selion.testcomponents;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.HashMap;5import java.util.Map;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.remote.RemoteWebDriver;8import org.testng.annotations.Test;9import com.paypal.selion.platform.grid.Grid;10import com.paypal.selion.platform.grid.Grid.driver;11import com.paypal.selion.platform.grid.GridManager;12public class RemoteNodeInformation {13 public void testRemoteNodeInfo() throws MalformedURLException {
RemoteNodeInformation
Using AI Code Generation
1import com.paypal.selion.platform.grid.Grid;2import com.paypal.selion.platform.grid.RemoteNodeInformation;3public class 3 {4 public static void main(String[] args) {5 RemoteNodeInformation[] nodes = Grid.getRemoteNodesInformation();6 for (RemoteNodeInformation node : nodes) {7 System.out.println(node.getRemoteHost());8 System.out.println(node.getRemotePort());9 System.out.println(node.getRemoteVersion());10 System.out.println(node.getRemoteOS());11 System.out.println(node.getRemoteArchitecture());12 }13 }14}
RemoteNodeInformation
Using AI Code Generation
1package com.paypal.selion.platform.grid;2import java.io.IOException;3import java.net.MalformedURLException;4import java.net.URL;5import java.util.ArrayList;6import java.util.List;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.remote.RemoteWebDriver;9public class RemoteNodeInformationTest {10 public static void main(String[] args) throws MalformedURLException, IOException {11 RemoteWebDriver driver = new RemoteWebDriver(url, DesiredCapabilities.firefox());12 System.out.println("Node Host: " + node.getHost());13 System.out.println("Node Port: " + node.getPort());14 System.out.println("Node OS: " + node.getOS());15 System.out.println("Node OS Arch: " + node.getOSArch());16 System.out.println("Node OS Version: " + node.getOSVersion());17 System.out.println("Node Available Processors: " + node.getAvailableProcessors());18 System.out.println("Node System Memory: " + node.getSystemMemory());19 System.out.println("Node Free Memory: " + node.getFreeMemory());20 System.out.println("Node Total Memory: " + node.getTotalMemory());21 System.out.println("Node Max Memory: " + node.getMaxMemory());22 System.out.println("Node Browser: " + node.getBrowser());23 System.out.println("Node Browser Version: " + node.getBrowserVersion());24 System.out.println("Node Browser Name: " + node.getBrowserName());25 System.out.println("Node Browser Platform: " + node.getBrowserPlatform());26 System.out.println("Node Browser Proxy: " + node.getBrowserProxy());27 System.out.println("Node Browser Proxy Port: " + node.getBrowserProxyPort());28 System.out.println("Node Browser Proxy Autoconfig: " + node.getBrowserProxyAutoconfig());29 System.out.println("Node Browser Proxy Autoconfig URL: " + node.getBrowserProxyAutoconfigURL());30 System.out.println("Node Browser Proxy Manual: " + node.getBrowserProxyManual());31 System.out.println("Node Browser Proxy Manual HTTP: " + node.getBrowserProxyManualHTTP());32 System.out.println("Node Browser Proxy Manual HTTPS: " + node.getBrowserProxyManualHTTPS());33 System.out.println("Node Browser Proxy Manual FTP: " + node.getBrowserProxyManualFTP());
RemoteNodeInformation
Using AI Code Generation
1import org.testng.annotations.Test;2import com.paypal.selion.platform.grid.RemoteNodeInformation;3public class RemoteNodeInformationTest {4 public void testRemoteNodeInformation() {5 RemoteNodeInformation remoteNodeInformation = new RemoteNodeInformation();6 System.out.println("Node IP: " + remoteNodeInformation.getIp());7 System.out.println("Node Hostname: " + remoteNodeInformation.getHostname());8 System.out.println("Node OS: " + remoteNodeInformation.getOs());9 System.out.println("Node Arch: " + remoteNodeInformation.getArch());10 System.out.println("Node Version: " + remoteNodeInformation.getVersion());11 }12}
RemoteNodeInformation
Using AI Code Generation
1import com.paypal.selion.platform.grid.RemoteNodeInformation;2import java.net.URL;3import java.util.List;4import java.util.Map;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.openqa.selenium.remote.RemoteWebDriver;7import org.testng.annotations.Test;8public class TestClass {9public void test() throws Exception {10DesiredCapabilities capabilities = new DesiredCapabilities();11capabilities.setBrowserName("firefox");12capabilities.setVersion("35");13capabilities.setCapability("platform", "WINDOWS");14String host = node.getHost();15System.out.println("Host name is " + host);16Map<String, Object> systemInfo = node.getSystemInfo();17System.out.println("System info is " + systemInfo);18List<String> logTypes = node.getLogTypes();19System.out.println("Log types are " + logTypes);20String log = node.getLog("server", 0);21System.out.println("Log is " + log);22}23}
RemoteNodeInformation
Using AI Code Generation
1import com.paypal.selion.platform.grid.RemoteNodeInformation;2import com.paypal.selion.platform.grid.Grid;3import com.paypal.selion.platform.grid.GridManagerFactory;4import java.util.Map;5import java.util.Set;6public class 3 {7public static void main(String[] args) {8Grid grid = GridManagerFactory.getGrid();9Set<RemoteNodeInformation> allNodes = grid.getAllNodes();10for (RemoteNodeInformation node : allNodes) {11System.out.println("Node: " + node.getHostName());12System.out.println("Node: " + node.getIpAddress());13System.out.println("Node: " + node.getUdid());14System.out.println("Node: " + node.getBrowserName());15System.out.println("Node: " + node.getBrowserVersion());16System.out.println("Node: " + node.getPlatformName());17System.out.println("Node: " + node.getPlatformVersion());18System.out.println("Node: " + node.getPlatformArchitecture());19System.out.println("Node: " + node.getPlatformLocale());20System.out.println("Node: " + node.getPlatformTimeZone());21System.out.println("Node: " + node.getDeviceName());22System.out.println("Node: " + node.getDeviceManufacturer());23System.out.println("Node: " + node.getDeviceModel());24System.out.println("Node: " + node.getDeviceScreenSize());25System.out.println("Node: " + node.getDeviceScreenDensity());26System.out.println("Node: " + node.getDeviceScreenOrientation());27System.out.println("Node: " + node.getDeviceUDID());28}29}30}
RemoteNodeInformation
Using AI Code Generation
1package com.paypal.selion.platform.grid;2import java.net.URL;3import org.openqa.grid.common.RegistrationRequest;4import org.openqa.grid.internal.RemoteProxy;5import org.openqa.grid.internal.utils.SelfRegisteringRemote;6import org.openqa.selenium.remote.DesiredCapabilities;7public class RemoteNodeInformation {8 public static void main(String[] args) throws Exception {9 RegistrationRequest rr = new RegistrationRequest();10 rr.addDesiredCapability(DesiredCapabilities.firefox());11 SelfRegisteringRemote remote = new SelfRegisteringRemote(rr);12 remote.startRemoteServer();13 remote.sendRegistrationRequest();14 RemoteProxy proxy = remote.getRemoteProxy();15 System.out.println("Node Information: " + proxy.getOriginalRegistrationRequest());16 remote.stopRemoteServer();17 }18}19package com.paypal.selion.platform.grid;20import java.net.URL;21import java.util.Set;22import org.openqa.grid.common.RegistrationRequest;23import org.openqa.grid.internal.RemoteProxy;24import org.openqa.grid.internal.utils.SelfRegisteringRemote;25import org.openqa.selenium.remote.DesiredCapabilities;26public class RemoteProxyInformation {27 public static void main(String[] args) throws Exception {28 RegistrationRequest rr = new RegistrationRequest();29 rr.addDesiredCapability(DesiredCapabilities.firefox());30 SelfRegisteringRemote remote = new SelfRegisteringRemote(rr);31 remote.startRemoteServer();32 remote.sendRegistrationRequest();33 RemoteProxy proxy = remote.getRemoteProxy();34 System.out.println("Node Information: " + proxy.getOriginalRegistrationRequest());35 Set<String> capabilities = proxy.getOriginalRegistrationRequest().getCapabilities();36 System.out.println("Capabilities: " + capabilities);37 remote.stopRemoteServer();38 }39}40package com.paypal.selion.platform.grid;41import java.net.URL;42import java.util.Set;43import org.openqa.grid.common.RegistrationRequest;44import org.openqa.grid.internal.RemoteProxy;45import org.openqa.grid.internal.utils.SelfRegisteringRemote;46import org.openqa.selenium.remote.DesiredCapabilities;
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!