Best SeLion code snippet using com.paypal.selion.configuration.LocalConfig
Source:ConfigManager.java
...19import net.jcip.annotations.ThreadSafe;20import org.apache.commons.lang.StringUtils;21import com.paypal.selion.logger.SeLionLogger;22/**23 * This class supports configuration operations on SeLion local configurations {@link LocalConfig} being used in TestNG24 * suites.25 * 26 * This supports configurations when running with parallel suites (i.e. TestNG parallel = {tests, methods, classes,27 * instances}) by supporting distinct local configurations for each TestNG xmltest. When reading config values without28 * parallel execution (parallel=false) values are effectively same as the value provided by {@link Config}29 * 30 * To get access to the SeLion local configuration values for the currently executing <test>.31 * 32 * <pre>33 * @Test34 * public void f(ITestContext ctx) {35 * String name = ctx.getCurrentXmlTest().getName();36 * LocalConfig config = ConfigManager.getConfig(name);37 * String Value = config.getConfigProperty(ConfigProperty.HOSTNAME);38 * }39 * </pre>40 * 41 * If the current <test> name can not be determined, then defaults to the global configuration that is available42 * via {@link Config#getConfigProperty(com.paypal.selion.configuration.Config.ConfigProperty)}/43 * {@link Config#setConfigProperty(com.paypal.selion.configuration.Config.ConfigProperty, Object)}.44 * 45 */46@ThreadSafe47public final class ConfigManager {48 // Map for each TestNG test name -> local SeLion config associated with <test>49 private static Map<String, LocalConfig> configsMap = new ConcurrentHashMap<String, LocalConfig>();50 private ConfigManager() {51 // Utility class. So hide the constructor52 }53 /**54 * Adds the local configuration {@link LocalConfig} associated with name. Over-rides any config with the same name.55 * 56 * @param config57 * The LocalConfig.58 * @param name59 * The name to associate with local config.60 */61 public static synchronized void addConfig(String name, LocalConfig config) {62 SeLionLogger.getLogger().entering(new Object[] { name, config });63 checkArgument(StringUtils.isNotBlank(name),64 "A testname for which configuration is being added cannot be null (or) empty.");65 checkArgument(config != null, "A configuration object cannot be null.");66 if (configsMap.containsKey(name)) {67 String message = "Overwriting an already existing configuration";68 SeLionLogger.getLogger().warning(message);69 }70 configsMap.put(name, config);71 SeLionLogger.getLogger().exiting();72 }73 /**74 * Returns the local configuration {@link LocalConfig} associated the provided name. If no config with that name has75 * been added an {@link IllegalArgumentException} is thrown.76 * 77 * <br>78 * 79 * <pre>80 * 81 * <b><i>Use this method for reading any "test-specific" configuration at any listener invocation.</b></i>82 * 83 * </pre>84 * 85 * @param name86 * The name to search for.87 * @return - A {@link LocalConfig} object that either represent's the configuration object that maps to the name88 * given (or) a default Configuration object that apes the global configuration.89 */90 public static synchronized LocalConfig getConfig(String name) {91 SeLionLogger.getLogger().entering(name);92 checkArgument(StringUtils.isNotBlank(name),93 "The test name for which configuration is being retrieved cannot be null (or) empty.");94 // if no local config added? I.e reading from a TestNG listener (before AddConfig) or listeners disabled?95 LocalConfig localConfiguration = configsMap.get(name);96 if (localConfiguration == null) {97 throw new IllegalArgumentException(98 "A local configuration with specified name was not found. Please double check the <test> name and retry.");99 }100 SeLionLogger.getLogger().exiting(localConfiguration);101 return localConfiguration;102 }103 /**104 * Remove the local configuration {@link LocalConfig} associated supplied name.105 * 106 * @param name107 * The name to remove108 * @return - <code>true</code> if the configuration was successfully removed.109 */110 public static synchronized boolean removeConfig(String name) {111 checkArgument(StringUtils.isNotBlank(name),112 "The test name for which configuration is being retrieved cannot be null (or) empty.");113 return configsMap.remove(name) != null ? true : false;114 }115 /**116 * A utility method that can dump the configuration for a given <test> identified with its name.117 * 118 * @param testName119 * - The name of the test as given in the suite xml file.120 */121 public static synchronized void printConfiguration(String testName) {122 LocalConfig currentConfig = getConfig(testName);123 currentConfig.printConfigValues(testName);124 }125 public static synchronized boolean isTestConfigPresent(String testName) {126 return configsMap.containsKey(testName);127 }128}...
Source:ConfigManagerTest.java
...17import static org.testng.Assert.assertTrue;18import org.testng.ITestContext;19import org.testng.annotations.Test;20import com.paypal.selion.configuration.ConfigManager;21import com.paypal.selion.configuration.LocalConfig;22import com.paypal.selion.configuration.Config.ConfigProperty;23import com.paypal.selion.platform.grid.BrowserFlavors;24public class ConfigManagerTest {25 private static final String TEST_CONFIG_NAME = "Test1";26 LocalConfig localConfig = new LocalConfig();27 String browserValue = BrowserFlavors.OPERA.getBrowser();28 @Test(groups = { "unit" })29 public void testAddConfig() {30 assertNotNull(localConfig, "could not get the SeLion local config");31 // Set new values in local config32 localConfig.setConfigProperty(ConfigProperty.BROWSER, BrowserFlavors.OPERA.getBrowser());33 ConfigManager.addConfig(TEST_CONFIG_NAME, localConfig);34 }35 @Test(groups = { "unit" }, dependsOnMethods = { "testAddConfig" })36 public void testGetConfig() {37 assertNotNull(localConfig, "Could not get the SeLion local config");38 LocalConfig testConfig = ConfigManager.getConfig(TEST_CONFIG_NAME);39 assertNotNull(testConfig);40 String newBrowserValue = testConfig.getConfigProperty(ConfigProperty.BROWSER);41 assertTrue(newBrowserValue.equals(browserValue), "value from local config is not equal to the value set");42 }43 @Test(groups = { "unit" }, dependsOnMethods = { "testGetConfig", "testAddConfig" })44 public void testRemoveConfig() {45 assertTrue(ConfigManager.removeConfig(TEST_CONFIG_NAME), "Remove config failed");46 }47 @Test(groups = { "unit" }, dependsOnMethods = { "testAddConfig" })48 public void testGetConfigProperty(ITestContext ctx) {49 String name = ctx.getCurrentXmlTest().getName();50 String browser = ConfigManager.getConfig(name).getConfigProperty(ConfigProperty.BROWSER);51 assertNotNull(browser);52 }...
LocalConfig
Using AI Code Generation
1import com.paypal.selion.configuration.LocalConfig;2import com.paypal.selion.platform.utilities.WebDriverWaitUtils;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.firefox.FirefoxDriver;7import org.openqa.selenium.support.ui.WebDriverWait;8import org.testng.annotations.Test;9public class TestClass {10 public void testMethod() {11 WebDriver driver = new FirefoxDriver();12 WebDriverWait wait = new WebDriverWait(driver, 30);13 driver.get(LocalConfig.getConfigProperty("url"));14 WebElement element = driver.findElement(By.name("q"));15 element.sendKeys("Selenium");16 element.submit();17 WebDriverWaitUtils.waitUntilElementIsVisible(By.name("btnG"));18 driver.quit();19 }20}21getConfigProperty(String key)22getConfigProperty(String key, String defaultValue)23setConfigProperty(String key, String value)24setConfigProperty(String key, String value, boolean persist)
LocalConfig
Using AI Code Generation
1import com.paypal.selion.configuration.LocalConfig;2import com.paypal.selion.platform.grid.Grid;3import com.paypal.selion.platform.grid.GridManager;4import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;5import com.paypal.selion.platform.grid.browsercapabilities.DesiredCapabilitiesBuilder;6import com.paypal.selion.platform.grid.browsercapabilities.DesiredCapabilitiesBuilder.Platform;7import com.paypal.selion.platform.grid.browsercapabilities.DesiredCapabilitiesBuilder.SupportedWebDriver;8import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder;9import com.paypal.selion.platform.grid.browsercapabilities.MobilePlatform;10import com.paypal.selion.platform.grid.browsercapabilities.MobileDevice;11import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceType;12import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileOS;13import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileOSVersion;14import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileBrowserType;15import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileBrowserVersion;16import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceOrientation;17import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceName;18import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDevicePlatform;19import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDevicePlatformVersion;20import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceScreenSize;21import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceUDID;22import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceAutomationName;23import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceAppPackage;24import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceAppActivity;25import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceAppWaitActivity;26import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceAppWaitPackage;27import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceApp;28import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceAppWaitDuration;29import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceAppiumVersion;30import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder.MobileDeviceFullReset;31import com.paypal.selion.platform.grid.browsercapabilities
LocalConfig
Using AI Code Generation
1package com.paypal.selion.testcomponents;2import com.paypal.selion.configuration.Config;3import com.paypal.selion.configuration.LocalConfig;4import com.paypal.selion.platform.grid.Grid;5import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;6import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilitiesBuilder;7import com.paypal.selion.platform.grid.browsercapabilities.SauceCapabilitiesBuilder;8import com.paypal.selion.platform.grid.browsercapabilities.WebDriverCapabilitiesBuilder;9import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform;10import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.Platform;11import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformType;12import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersion;13import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType;14import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType;15import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType.BrowserType;16import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType.BrowserType.Browser;17import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType.BrowserType.BrowserVersion;18import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType.BrowserType.BrowserVersion.BrowserVersionValue;19import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType.BrowserType.BrowserVersion.BrowserVersionValue.BrowserVersionValueKey;20import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType.BrowserType.BrowserVersion.BrowserVersionValue.BrowserVersionValueKey.BrowserVersionValueKeyKey;21import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType.BrowserType.BrowserVersion.BrowserVersionValue.BrowserVersionValueKey.BrowserVersionValueKeyKey.BrowserVersionValueKeyKeyKey;22import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType.BrowserType.BrowserVersion.BrowserVersionValue.BrowserVersionValueKey.BrowserVersionValueKeyKey.BrowserVersionValueKeyKeyKey.BrowserVersionValueKeyKeyKeyKey;23import com.paypal.selion.platform.grid.browsercapabilities.WebDriverPlatform.PlatformVersionType.BrowserVersionType.BrowserType.BrowserVersion.B
LocalConfig
Using AI Code Generation
1import com.paypal.selion.configuration.LocalConfig;2import com.paypal.selion.platform.grid.Grid;3import com.paypal.selion.platform.html.Label;4import com.paypal.selion.platform.html.TextField;5import com.paypal.selion.platform.utilities.WebDriverWaitUtils;6import org.openqa.selenium.By;7import org.openqa.selenium.support.ui.ExpectedConditions;8public class Test1 {9public static void main(String[] args) {10Grid.driver().get(LocalConfig.getConfigProperty("app.url"));11TextField email = new TextField(By.id("email"));12TextField password = new TextField(By.id("password"));13Label loginbutton = new Label(By.id("loginbutton"));14email.type("
LocalConfig
Using AI Code Generation
1import com.paypal.selion.configuration.LocalConfig;2import com.paypal.selion.configuration.LocalConfig;3public class LocalConfigExample {4 public static void main(String[] args) {5 String value = LocalConfig.getConfigProperty("key");6 LocalConfig.setConfigProperty("key", "value");7 }8}9 < version > ${selion.version} </ version > 10 < version > ${selion.version} </ version > 11 < version > ${selion.version} </ version >
LocalConfig
Using AI Code Generation
1import com.paypal.selion.configuration.LocalConfig;2public class LocalConfigTest {3 public static void main(String[] args) {4 LocalConfig lc = LocalConfig.getDefaultConfig();5 String platform = lc.getPlatform();6 System.out.println("platform is " + platform);7 }8}9import com.paypal.selion.configuration.LocalConfig;10public class LocalConfigTest {11 public static void main(String[] args) {12 LocalConfig lc = LocalConfig.getDefaultConfig();13 String deviceName = lc.getMobileDeviceName();14 System.out.println("deviceName is " + deviceName);15 }16}17import com.paypal.selion.configuration.LocalConfig;18public class LocalConfigTest {19 public static void main(String[] args) {20 LocalConfig lc = LocalConfig.getDefaultConfig();21 String deviceVersion = lc.getMobileDeviceVersion();22 System.out.println("deviceVersion is " + deviceVersion);23 }24}25import com.paypal.selion.configuration.LocalConfig;26public class LocalConfigTest {27 public static void main(String[] args) {28 LocalConfig lc = LocalConfig.getDefaultConfig();29 String deviceOrientation = lc.getMobileDeviceOrientation();30 System.out.println("deviceOrientation is " + deviceOrientation);31 }32}33import com.paypal.selion.configuration.LocalConfig;34public class LocalConfigTest {35 public static void main(String[] args) {36 LocalConfig lc = LocalConfig.getDefaultConfig();37 String deviceLanguage = lc.getMobileDeviceLanguage();38 System.out.println("
LocalConfig
Using AI Code Generation
1package com.paypal.selion.configuration;2import java.io.File;3import java.util.Map;4import org.apache.commons.lang.StringUtils;5import org.apache.commons.lang.SystemUtils;6import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;7import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;8import org.openqa.grid.internal.utils.configuration.StandaloneConfiguration;9import org.openqa.selenium.remote.server.SeleniumServer;10public class LocalConfig {11 private static final String SELENIUM_SERVER_JAR = "selenium-server-standalone.jar";12 private static final String SELENIUM_SERVER_JAR_PATH = "lib" + File.separator + SELENIUM_SERVER_JAR;13 private static final String SELENIUM_SERVER_JAR_PATH_WINDOWS = "lib" + File.separator + SELENIUM_SERVER_JAR;14 private static final String SELENIUM_SERVER_JAR_PATH_MAC = "lib" + File.separator + SELENIUM_SERVER_JAR;15 private static final String SELENIUM_SERVER_JAR_PATH_LINUX = "lib" + File.separator + SELENIUM_SERVER_JAR;16 private static final String SELENIUM_SERVER_JAR_PATH_SOLARIS = "lib" + File.separator + SELENIUM_SERVER_JAR;17 private static final String SELENIUM_NODE_JAR = "selenium-server-standalone.jar";18 private static final String SELENIUM_NODE_JAR_PATH = "lib" + File.separator + SELENIUM_NODE_JAR;19 private static final String SELENIUM_NODE_JAR_PATH_WINDOWS = "lib" + File.separator + SELENIUM_NODE_JAR;20 private static final String SELENIUM_NODE_JAR_PATH_MAC = "lib" + File.separator + SELENIUM_NODE_JAR;21 private static final String SELENIUM_NODE_JAR_PATH_LINUX = "lib" + File.separator + SELENIUM_NODE_JAR;22 private static final String SELENIUM_NODE_JAR_PATH_SOLARIS = "lib" + File.separator + SELENIUM_NODE_JAR;23 private static final String SELENIUM_HUB_JAR = "selenium-server-standalone.jar";24 private static final String SELENIUM_HUB_JAR_PATH = "lib" + File.separator + SELENIUM_HUB_JAR;
LocalConfig
Using AI Code Generation
1package com.paypal.selion.testscripts;2import org.testng.annotations.Test;3import com.paypal.selion.configuration.Config;4import com.paypal.selion.configuration.LocalConfig;5public class TestLocalConfig {6 public void testLocalConfig() {7 LocalConfig config = Config.getConfig(LocalConfig.class);8 System.out.println(config.getBrowser());9 System.out.println(config.getPlatform());10 System.out.println(config.getDeviceName());11 }12}13package com.paypal.selion.testscripts;14import org.testng.annotations.Test;15import com.paypal.selion.configuration.Config;16import com.paypal.selion.configuration.LocalConfig;17public class TestLocalConfig {18 public void testLocalConfig() {19 LocalConfig config = Config.getConfig(LocalConfig.class);20 config.setBrowser("chrome");21 config.setPlatform("MAC");22 config.setDeviceName("emulator-5554");23 }24}25package com.paypal.selion.testscripts;26import org.testng.annotations.Test;27import com.paypal.selion.configuration.Config;28import com.paypal.selion.configuration.LocalConfig;29public class TestLocalConfig {30 public void testLocalConfig() {31 LocalConfig config = Config.getConfig(LocalConfig.class);32 config.setBrowser("chrome");33 config.setPlatform("MAC");34 config.setDeviceName("emulator-5554");35 config.setDeviceOrientation("PORTRAIT");36 }37}38package com.paypal.selion.testscripts;39import org.testng.annotations.Test;40import com.paypal.selion.configuration.Config;41import com.paypal.selion.configuration.LocalConfig;42public class TestLocalConfig {43 public void testLocalConfig() {44 LocalConfig config = Config.getConfig(LocalConfig.class);45 config.setBrowser("chrome");46 config.setPlatform("
LocalConfig
Using AI Code Generation
1import com.paypal.selion.configuration.LocalConfig;2public class LocalConfigTest {3 public static void main(String[] args) {4 String browser = LocalConfig.getDefaultConfig().getString("browser");5 System.out.println(browser);6 }7}8import com.paypal.selion.configuration.LocalConfig;9public class LocalConfigTest {10 public static void main(String[] args) {11 String browser = LocalConfig.getDefaultConfig().getString("browser");12 System.out.println(browser);13 }14}15import com.paypal.selion.configuration.LocalConfig;16public class LocalConfigTest {17 public static void main(String[] args) {18 String browser = LocalConfig.getDefaultConfig().getString("browser");19 System.out.println(browser);20 }21}22import com.paypal.selion.configuration.LocalConfig;23public class LocalConfigTest {24 public static void main(String[] args) {25 String browser = LocalConfig.getDefaultConfig().getString("browser");26 System.out.println(browser);27 }28}29import com.paypal.selion.configuration.LocalConfig;30public class LocalConfigTest {31 public static void main(String[] args) {
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!!