How to use Properties method of com.qaprosoft.carina.core.foundation.utils.resources.L10N class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.utils.resources.L10N.Properties

Source:AbstractTest.java Github

copy

Full Screen

...183 // moved from UITest->executeBeforeTestSuite184 String customCapabilities = Configuration.get(Parameter.CUSTOM_CAPABILITIES);185 if (!customCapabilities.isEmpty()) {186 //redefine core properties using custom capabilities file187 Map<String, String> properties = Configuration.loadCoreProperties(customCapabilities);188 //reregister device if mobile core properties are redefined 189 DevicePool.addDevice(properties);190 }191 }192 193 @BeforeClass(alwaysRun = true)194 public void executeBeforeTestClass(ITestContext context) throws Throwable {195 // do nothing for now196 }197 @AfterClass(alwaysRun = true)198 public void executeAfterTestClass(ITestContext context) throws Throwable {199 if (Configuration.getDriverMode() == DriverMode.CLASS_MODE) {200 LOGGER.debug("Deinitialize driver(s) in UITest->AfterClass.");201 quitDrivers();...

Full Screen

Full Screen

Source:L10N.java Github

copy

Full Screen

1/*2 * Copyright 2013-2015 QAPROSOFT (http://qaprosoft.com/).3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.qaprosoft.carina.core.foundation.utils.resources;17import java.net.URL;18import java.util.ArrayList;19import java.util.Iterator;20import java.util.List;21import java.util.Locale;22import java.util.MissingResourceException;23import java.util.ResourceBundle;24import org.apache.commons.io.FilenameUtils;25import org.apache.commons.lang3.StringUtils;26import org.apache.log4j.Logger;27import com.qaprosoft.carina.core.foundation.utils.Configuration;28import com.qaprosoft.carina.core.foundation.utils.SpecialKeywords;29import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;30/*31 * QUALITY-1076:32 * http://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html33 * Need to set useSystemClassLoader=false for maven surefire plugin to receive access to classloader L10N files on CI34 * <plugin>35 <groupId>org.apache.maven.plugins</groupId>36 <artifactId>maven-surefire-plugin</artifactId>37 <version>2.18.1</version>38 <configuration>39 <useSystemClassLoader>false</useSystemClassLoader>40 </configuration>41 */42public class L10N {43 protected static final Logger LOGGER = Logger.getLogger(L10N.class);44 private static ArrayList<ResourceBundle> resBoundles = new ArrayList<ResourceBundle>();45 public static void init() {46 if (!Configuration.getBoolean(Parameter.ENABLE_L10N)) {47 return;48 }49 50 List<Locale> locales = LocaleReader.init(Configuration51 .get(Parameter.LOCALE));52 53 List<String> loadedResources = new ArrayList<String>();54 for (URL u : Resources.getResourceURLs(new ResourceURLFilter() {55 public @Override56 boolean accept(URL u) {57 LOGGER.debug("L10N: file URL: " + u);58 String s = u.getPath();59 return s.contains(SpecialKeywords.L10N);60 }61 })) {62 LOGGER.debug(String.format(63 "Analyzing '%s' L10N resource for loading...", u));64 // workable examples for resource loading are65 // ResourceBundle.getBundle("L10N.messages", locale);66 // ResourceBundle.getBundle("L10N.system.data-access.resources.gwt.datasourceAdminDialog",67 // locale);68 /*69 * 2. Exclude localization resources like such L10N.messages_de,70 * L10N.messages_ptBR etc... Note: we ignore valid resources if 3rd71 * or 5th char from the end is "_". As designed :(72 */73 String fileName = FilenameUtils.getBaseName(u.getPath());74 if (u.getPath().endsWith("L10N.class")75 || u.getPath().endsWith("L10N$1.class")) {76 // separate conditions to support core JUnit tests77 continue;78 }79 if (fileName.lastIndexOf('_') == fileName.length() - 380 || fileName.lastIndexOf('_') == fileName.length() - 5) {81 LOGGER.debug(String82 .format("'%s' resource IGNORED as it looks like localized resource!",83 fileName));84 continue;85 }86 /*87 * convert "file:88 * E:\pentaho\qa-automation\target\classes\L10N\messages89 * .properties" to "L10N.messages"90 */91 String filePath = FilenameUtils.getPath(u.getPath());92 int index = filePath.indexOf(SpecialKeywords.L10N);93 94 if (index == -1) {95 LOGGER.warn("Unable to find L10N pattern for " + u.getPath() + " resource!");96 continue;97 }98 String resource = filePath.substring(99 filePath.indexOf(SpecialKeywords.L10N))100 .replaceAll("/", ".")101 + fileName;102 if (!loadedResources.contains(resource)) {103 loadedResources.add(resource);104 try {105 LOGGER.debug(String.format("Adding '%s' resource...",106 resource));107 for (Locale locale : locales) {108 resBoundles.add(ResourceBundle.getBundle(resource, locale));109 }110 LOGGER.debug(String111 .format("Resource '%s' added.", resource));112 } catch (MissingResourceException e) {113 LOGGER.debug(e);114 }115 } else {116 LOGGER.debug(String117 .format("Requested resource '%s' is already loaded into the ResourceBundle!",118 resource));119 }120 }121 LOGGER.debug("init: L10N bundle size: " + resBoundles.size());122 }123 /**124 * get Default Locale125 * @return Locale126 */127 public static Locale getDefaultLocale() {128 List<Locale> locales = LocaleReader.init(Configuration129 .get(Parameter.LOCALE));130 131 if (locales.size() == 0) {132 throw new RuntimeException("Undefined default locale specified! Review 'locale' setting in _config.properties.");133 }134 return locales.get(0);135 }136 137 /**138 * getText by key for default locale.139 * 140 * @param key141 * - String142 * 143 * @return String144 */145 public static String getText(String key) {146 return getText(key, getDefaultLocale());147 }148 149 150 /**151 * getText for specified locale and key.152 * 153 * @param key154 * - String155 * @param locale156 * - Locale157 * @return String158 */159 public static String getText(String key, Locale locale) {160 LOGGER.debug("getText: L10N bundle size: " + resBoundles.size());161 Iterator<ResourceBundle> iter = resBoundles.iterator();162 while (iter.hasNext()) {163 ResourceBundle bundle = iter.next();164 try {165 String value = bundle.getString(key);166 LOGGER.debug("Looking for value for locale:'"167 + locale.toString()168 + "' current iteration locale is: '"169 + bundle.getLocale().toString() + "'.");170 if (bundle.getLocale().toString().equals(locale.toString())) {171 LOGGER.debug("Found locale:'" + locale.toString()172 + "' and value is '" + value + "'.");173 return value;174 }175 } catch (MissingResourceException e) {176 // do nothing177 }178 }179 return key;180 }181 /*182 * QUALITY-1282: This method helps when translating strings that have single183 * quotes or other special characters that get omitted.184 */185 public static String formatString(String resource, String... parameters) {186 for (int i = 0; i < parameters.length; i++) {187 resource = resource.replace("{" + i + "}", parameters[i]);188 LOGGER.debug("Localized string value is: " + resource);189 }190 return resource;191 }192 /*193 * Make sure you remove the single quotes around %s in xpath as string194 * returned will either have it added for you or single quotes won't be195 * added as concat() doesn't need them.196 */197 public static String generateConcatForXPath(String xpathString) {198 String returnString = "";199 String searchString = xpathString;200 char[] quoteChars = new char[] { '\'', '"' };201 int quotePos = StringUtils.indexOfAny(searchString, quoteChars);202 if (quotePos == -1) {203 returnString = "'" + searchString + "'";204 } else {205 returnString = "concat(";206 LOGGER.debug("Current concatenation: " + returnString);207 while (quotePos != -1) {208 String subString = searchString.substring(0, quotePos);209 returnString += "'" + subString + "', ";210 LOGGER.debug("Current concatenation: " + returnString);211 if (searchString.substring(quotePos, quotePos + 1).equals("'")) {212 returnString += "\"'\", ";213 LOGGER.debug("Current concatenation: " + returnString);214 } else {215 returnString += "'\"', ";216 LOGGER.debug("Current concatenation: " + returnString);217 }218 searchString = searchString.substring(quotePos + 1,219 searchString.length());220 quotePos = StringUtils.indexOfAny(searchString, quoteChars);221 }222 returnString += "'" + searchString + "')";223 LOGGER.debug("Concatenation result: " + returnString);224 }225 return returnString;226 }227}...

Full Screen

Full Screen

Source:WebLocalizationSample.java Github

copy

Full Screen

1/*******************************************************************************2 * Copyright 2013-2020 QaProSoft (http://www.qaprosoft.com).3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 *******************************************************************************/16package com.qaprosoft.carina.demo;17import com.qaprosoft.carina.core.foundation.AbstractTest;18import com.qaprosoft.carina.core.foundation.utils.Configuration;19import com.qaprosoft.carina.core.foundation.utils.ownership.MethodOwner;20import com.qaprosoft.carina.core.foundation.utils.resources.L10N;21import com.qaprosoft.carina.core.foundation.utils.resources.L10Nparser;22import com.qaprosoft.carina.demo.gui.pages.localizationSample.WikipediaHomePage;23import com.qaprosoft.carina.demo.gui.pages.localizationSample.WikipediaLocalePage;24import com.zebrunner.agent.core.annotation.TestLabel;25import org.slf4j.Logger;26import org.slf4j.LoggerFactory;27import org.testng.annotations.Test;28import org.testng.asserts.SoftAssert;29import java.lang.invoke.MethodHandles;30import java.util.Locale;31/**32 * This sample shows how create Web Localization test with Resource Bundle.33 *34 * @author qpsdemo35 */36public class WebLocalizationSample extends AbstractTest {37 private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());38 @Test39 @MethodOwner(owner = "qpsdemo")40 @TestLabel(name = "feature", value = "l10n")41 public void testLanguages() {42 WikipediaHomePage wikipediaHomePage = new WikipediaHomePage(getDriver());43 wikipediaHomePage.open();44 SoftAssert softAssert = new SoftAssert();45 WikipediaLocalePage wikipediaLocalePage = wikipediaHomePage.goToWikipediaLocalePage(getDriver());46 String welcomeText = wikipediaLocalePage.getWelcomeText();47 String expectedWelcomeText = L10N.getText("HomePage.welcomeText");48 softAssert.assertEquals(welcomeText, expectedWelcomeText.trim(), "Wikipedia welcome text was not the expected.");49 wikipediaLocalePage.clickDiscussionBtn();50 String expectedDiscussionText = L10N.getText("discussionElem");51 String discussionText = wikipediaLocalePage.getDiscussionText();52 softAssert.assertEquals(discussionText,expectedDiscussionText.trim(),"Wikipedia discussion text was not the expected");53 softAssert.assertAll();54 }55 @Test56 @MethodOwner(owner = "qpsdemo")57 @TestLabel(name = "feature", value = "l10n")58 /**59 * _config.properties should be filled correctly.60 * For example: for Japan language you should use:61 * locale=ja_JP62 *63 * add_new_localization=true - for creation and false for checking.64 * add_new_localization_path=./src/main/resources/L10N/ - path for newly created l10n file65 * add_new_localization_encoding=UTF-8 (use ISO-2022-JP if you can't have UTF-8 property file or there are issues with comparison or interaction)66 * add_new_localization_property_name=new_locale_ - name of l10n file. Copy all required values in your existing locale_ja_JP.properties67 * Read more details in com.qaprosoft.carina.core.foundation.utils.resources.L10Nparser68 */69 public void testAddNewLanguages() {70 WikipediaHomePage wikipediaHomePage = new WikipediaHomePage(getDriver());71 wikipediaHomePage.open();72 WikipediaLocalePage wikipediaLocalePage = wikipediaHomePage.goToWikipediaLocalePage(getDriver());73 String expectedWelcomeText = L10N.getText("HomePage.welcomeText");74 String welcomeText = wikipediaLocalePage.getWelcomeText();75 SoftAssert sa = new SoftAssert();76 sa.assertEquals(welcomeText, expectedWelcomeText.trim(), "Wikipedia welcome text was not the expected.");77 // To set correct locale for creating new localization text.78 // Can be changed dynamically during test execution.79 L10Nparser.setActualLocale(Configuration.get(Configuration.Parameter.LOCALE));80 Locale actualLocale = L10Nparser.getActualLocale();81 LOGGER.info(actualLocale.toString());82 sa.assertTrue(wikipediaLocalePage.checkMultipleLocalization(), "Localization error: " + L10Nparser.getAssertErrorMsg());83 L10Nparser.saveLocalization();84 sa.assertAll();85 }86}...

Full Screen

Full Screen

Properties

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.Assert;3import org.testng.annotations.Test;4import com.qaprosoft.carina.core.foundation.utils.resources.L10N;5public class L10NTest {6public void testL10N() {7String value = L10N.get("key1");8System.out.println(value);9Assert.assertTrue(value.equals("value1"));10}11}12package com.qaprosoft.carina.demo;13import org.testng.Assert;14import org.testng.annotations.Test;15import com.qaprosoft.carina.core.foundation.utils.resources.L10N;16public class L10NTest {17public void testL10N() {18String value = L10N.get("key2");19System.out.println(value);20Assert.assertTrue(value.equals("value2"));21}22}23package com.qaprosoft.carina.demo;24import org.testng.Assert;25import org.testng.annotations.Test;26import com.qaprosoft.carina.core.foundation.utils.resources.L10N;27public class L10NTest {28public void testL10N() {29String value = L10N.get("key3");30System.out.println(value);31Assert.assertTrue(value.equals("value3"));32}33}34package com.qaprosoft.carina.demo;35import org.testng.Assert;36import org.testng.annotations.Test;37import com.qaprosoft.carina.core.foundation.utils.resources.L10N;38public class L10NTest {39public void testL10N() {40String value = L10N.get("key4");41System.out.println(value);42Assert.assertTrue(value.equals("value4"));43}44}

Full Screen

Full Screen

Properties

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.resources.L10N;2public class TestProperties {3 public static void main(String[] args) {4 System.out.println(L10N.get("test1"));5 System.out.println(L10N.get("test2"));6 System.out.println(L10N.get("test3"));7 System.out.println(L10N.get("test4"));8 System.out.println(L10N.get("test5"));9 System.out.println(L10N.get("test1", "default value"));10 System.out.println(L10N.get("test2", "default value"));11 System.out.println(L10N.get("test3", "default value"));12 System.out.println(L10N.get("test4", "default value"));13 System.out.println(L10N.get("test5", "default value"));14 }15}16import com.qaprosoft.carina.core.foundation.utils.resources.L10N;17public class TestProperties {18 public static void main(String[] args) {19 System.out.println(L10N.get("test1", "en"));20 System.out.println(L10N.get("test2", "en"));21 System.out.println(L10N.get("test3", "en"));22 System.out.println(L10N.get("test4", "en"));23 System.out.println(L10N.get("test5", "en"));24 System.out.println(L10N.get("test1", "en", "default value"));25 System.out.println(L10N.get("test2", "en", "default value"));26 System.out.println(L10N.get("test3", "en", "default value"));27 System.out.println(L10N.get("test4", "en", "default value"));28 System.out.println(L10N.get("test5", "en", "default value"));29 }30}

Full Screen

Full Screen

Properties

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.core.foundation.utils.resources;2import java.util.Properties;3import com.qaprosoft.carina.core.foundation.utils.resources.L10N;4public class Test {5public static void main(String[] args) {6Properties prop = L10N.getLocalizedProperties("test.properties");7String value = prop.getProperty("test");8System.out.println(value);9}10}11package com.qaprosoft.carina.core.foundation.utils.resources;12import com.qaprosoft.carina.core.foundation.utils.resources.L10N;13public class Test {14public static void main(String[] args) {15String value = L10N.getLocalizedValue("test.properties", "test");16System.out.println(value);17}18}19package com.qaprosoft.carina.core.foundation.utils.resources;20import com.qaprosoft.carina.core.foundation.utils.resources.L10N;21public class Test {22public static void main(String[] args) {23String value = L10N.getLocalizedValue("test.properties", "test");24System.out.println(value);25}26}27package com.qaprosoft.carina.core.foundation.utils.resources;28import java.util.Properties;29import com.qaprosoft.carina.core.foundation.utils.resources.L10N;30public class Test {31public static void main(String[] args) {32String value = L10N.getValue("test.properties", "test");33System.out.println(value);34}35}36package com.qaprosoft.carina.core.foundation.utils.resources;37import java.util.Properties;38import com.qaprosoft.carina.core.foundation.utils.resources.L10N;39public class Test {40public static void main(String[] args) {

Full Screen

Full Screen

Properties

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.resources.L10N;2import java.io.IOException;3import java.util.Properties;4public class 1 {5public static void main(String[] args) throws IOException {6Properties prop = new Properties();7prop.load(L10N.class.getResourceAsStream("en.properties"));8String value = prop.getProperty("hello");9System.out.println(value);10}11}12package com.qaprosoft.carina.core.foundation.utils.resources;13import java.io.IOException;14import java.util.Properties;15import org.apache.log4j.Logger;16import com.qaprosoft.carina.core.foundation.utils

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.

Run Carina automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful