Best Testng code snippet using org.testng.util.Strings.isNotNullAndNotEmpty
Source:APIResponse_Queue_ValidationTest.java
...29 // Execute first busy request30 Response submitResponse = executeSubmitReq(httpRequest, groovyScript);31 SubmitEPResponse submitEPResponse = getGson().fromJson(submitResponse.asString(), SubmitEPResponse.class);32 Assert.assertEquals(submitResponse.getStatusCode(), 200, "First request to keep processor busy failed");33 Assert.assertTrue(Strings.isNotNullAndNotEmpty(submitEPResponse.getId()));34 }35 /**36 * Method to send another submit API request which will keep the processor busy37 * for certain amount of time38 */39 @Test(priority = 2)40 public void SubmitEPTest_SecondBusyRequest() throws InterruptedException {41 String groovyScript = String.format("Thread.sleep(%s)", r.nextInt(11000, 12000));42 RequestSpecification httpRequest = getRequest("user_1", "pass_1");43 // Execute second busy request44 Response submitResponse = executeSubmitReq(httpRequest, groovyScript);45 SubmitEPResponse submitEPResponse = getGson().fromJson(submitResponse.asString(), SubmitEPResponse.class);46 Assert.assertEquals(submitResponse.getStatusCode(), 200, "Second request to keep processor busy failed");47 Assert.assertTrue(Strings.isNotNullAndNotEmpty(submitEPResponse.getId()));48 }49 /**50 * Method to send third submit API request request should remain queued with51 * status as "Pending' until process becomes free52 */53 @Test(priority = 3)54 public void SubmitEPTest_FirstQueueRequest() {55 double number1 = Math.random();56 double number2 = Math.random();57 String groovyScript = String.format("%s+%s", number1, number2);58 RequestSpecification httpRequest = getRequest("user_1", "pass_1");59 Response submitResponse = executeSubmitReq(httpRequest, groovyScript);60 SubmitEPResponse submitEPResponse = getGson().fromJson(submitResponse.asString(), SubmitEPResponse.class);61 Assert.assertEquals(submitResponse.getStatusCode(), 200, "First queued request failed");62 Assert.assertTrue(Strings.isNotNullAndNotEmpty(submitEPResponse.getId()));63 }64 /**65 * Method to send fourth submit API request request should remain queued with66 * status as "Pending' until process becomes free67 */68 @Test(priority = 4)69 public void SubmitEPTest_SecondQueueRequest() {70 double number1 = Math.random();71 double number2 = Math.random();72 String groovyScript = String.format("%s+%s", number1, number2);73 RequestSpecification httpRequest = getRequest("user_1", "pass_1");74 Response submitResponse = executeSubmitReq(httpRequest, groovyScript);75 SubmitEPResponse submitEPResponse = getGson().fromJson(submitResponse.asString(), SubmitEPResponse.class);76 Assert.assertEquals(submitResponse.getStatusCode(), 200, "Second request queuing failed");77 Assert.assertTrue(Strings.isNotNullAndNotEmpty(submitEPResponse.getId()));78 }79 /**80 * Method to send fifth submit API request request should remain queued with81 * status as "Pending' until process becomes free Test is failed - only 282 * requests can remain in queue at a time83 */84 @Test(priority = 5)85 public void SubmitEPTest_ThirdQueueRequest() throws InterruptedException {86 double number1 = Math.random();87 double number2 = Math.random();88 String groovyScript = String.format("%s+%s", number1, number2);89 RequestSpecification httpRequest = getRequest("user_1", "pass_1");90 Response submitResponse = executeSubmitReq(httpRequest, groovyScript);91 SubmitEPResponse submitEPResponse = getGson().fromJson(submitResponse.asString(), SubmitEPResponse.class);92 Assert.assertEquals(submitResponse.getStatusCode(), 200, "Third request queing failed");93 Assert.assertTrue(Strings.isNotNullAndNotEmpty(submitEPResponse.getId()));94 Thread.sleep(12000);95 }96 @AfterMethod97 public void afterMethod(ITestResult result) {98 printTestResults(result);99 }100}...
Source:DataProviderTest_Kontakt.java
...39 Assert.assertEquals(startseitePageObject.getTextOfTitle(),"Wir automatisieren Browser mit Liebe und Leidenschaft.");40 startseitePageObject.topMenuPageObject.clickKontakt();41 KontaktPageObject kontaktPageObject = new KontaktPageObject();42 Assert.assertEquals(kontaktPageObject.getTextOfTitle(),"In Kontakt kommen");43 if(Strings.isNotNullAndNotEmpty(name)){44 kontaktPageObject.enterName(name);45 }46 if(Strings.isNotNullAndNotEmpty(email)){47 kontaktPageObject.enterEmail(email);48 }49 if(Strings.isNotNullAndNotEmpty(phone)){50 kontaktPageObject.enterPhone(phone);51 }52 if(Strings.isNotNullAndNotEmpty(nachricht)){53 kontaktPageObject.enterNachricht(nachricht);54 }55 kontaktPageObject.clickAbsenden();56 Assert.assertEquals(kontaktPageObject.getTextOfFehlermeldungList(0), ersteFehlermessage, "Erste Fehlermeldung");57 Assert.assertEquals(kontaktPageObject.getSizeOfFehlermeldungList(), anzFehler, "Erwartete Fehlermeldungen");58 }59 @DataProvider(parallel = false)60 public Object[][] kontaktProvider() {61 return new Object[][]{62 {"Michel", "no Vailid", "052 000 00 00", "Message", "Bitte geben Sie eine gültige E-Mail-Adresse ein.", 2},63 {"", "info@selenium-consulting.ch", "", "Message", "Dies ist ein Pflichtfeld.", 2},64 {"", "", "", "", "Dies ist ein Pflichtfeld.", 4},65 };66 }...
Source:AllianceController.java
...38 }39 @RequestMapping(value = "/selectByIp", method = RequestMethod.GET)40 public AllianceEntity selectByAllianceIp(String allianceIp, HttpServletRequest request) {41 //å¦æIP为空42 if (Strings.isNotNullAndNotEmpty(allianceIp)) {43 return null;44 }45 //IPæ ¼å¼ä¸å¯¹46 if (!isIp(allianceIp)) {47 return null;48 }49 //请æ±ä¸æ¥æ¾çä¸ä¸æ · 说ææ¯éæ³è¯·æ±50 if (!IpUtil.getIpAddr(request).equals(allianceIp)) {51 return null;52 }53 return allianceService.findByAllianceIp(allianceIp);54 }55 @RequestMapping(value = "/insert", method = RequestMethod.GET)56 public String insertIntoAlliance(String allianceIp, String allianceId, String allianceName) {57 //å¦æIp为空58 if (Strings.isNotNullAndNotEmpty(allianceIp) ||59 Strings.isNotNullAndNotEmpty(allianceId) ||60 Strings.isNotNullAndNotEmpty(allianceName)) {61 return "è¾å
¥åæ°æ空å¼ï¼è¯·å°ææå
容填åå®æ´";62 }63 //Ipæ ¼å¼ä¸å¯¹64 if(!isIp(allianceIp)) {65 return "IPå°åæ ¼å¼ä¸å¯¹";66 }67 allianceService.insertIntoAlliance(allianceIp, allianceId, allianceName);68 return JSON.toJSONString(keySuitService.getRandowKeySuit());69 }70 //éªè¯æ¯å¦æ¯IPå°å71 private boolean isIp(String allianceIp) {72 //IPå°åä¸è½ä¸ºç©º73 if (Strings.isNotNullAndNotEmpty(allianceIp)) {74 return false;75 }76 //IPå°åæ¯ç¨ . åéç77 if (!allianceIp.contains(".")) {78 return false;79 }80 //IPå°åæ¯123.123.123.123æ ¼å¼æå¯ä»¥81 if (!allianceIp.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}")) {82 return false;83 }84 List<String> list = Splitter.on(".").splitToList(allianceIp);85 for (String str : list) {86 int value = Integer.parseInt(str);87 if (value < 255 && value > 0) {...
Source:TableGenerator.java
...53 result.append(54 format(55 TABLE_LINE,56 ++testNumber,57 Strings.isNotNullAndNotEmpty(test.getEpic()) ? test.getEpic() : " ",58 Strings.isNotNullAndNotEmpty(test.getFeature()) ? test.getFeature() : " ",59 Strings.isNotNullAndNotEmpty(test.getStory()) ? test.getStory() : " ",60 colorValue,61 getColorName(test.getStatus()),62 colorValue,63 test.getName()64 )65 );66 }67 return result.toString();68 }69}...
Source:DataProviderTest_Contact.java
...36 ,String message37 ,int errorSize){38 Home home = AbstractSeleniumToolkitPageObject.loadSeleniumToolkitPage();39 GetStarted getStarted = home.topMenuPageObject.clickGetStartedMenu();40 if(Strings.isNotNullAndNotEmpty(name)){41 getStarted.enterName(name);42 }43 if(Strings.isNotNullAndNotEmpty(email)){44 getStarted.enterEmail(email);45 }46 if(Strings.isNotNullAndNotEmpty(phone)){47 getStarted.enterPhoneNumber(phone);48 }49 if(Strings.isNotNullAndNotEmpty(message)){50 getStarted.enterMessage(message);51 }52 getStarted.clickSubmitButton();53 ReportAssert.assertEquals(getStarted.getErrorFieldSize(), errorSize, "Test the Size of Errorlist");54 }55 56 @DataProvider(parallel = true)57 public Object[][] contactProvider() {58 return new Object[][]{59 {"Michel", "no Vailid", "052 000 00 00", "", 3},60 {"Michel", "info@selenium-toolkit.com", "", "", 2},61 };62 }63 @DataProvider(parallel = false)...
Source:PickingActionTest.java
...26 PickingTaskDataList dataList = resp.asJson();27 assertThat("count task items", dataList.getItems(), hasSize(pageSize));28 for (PickingTaskData pickingTaskData : dataList.getItems()) {29 String desc = String.format("TaskId: %s, invalid field value: ", pickingTaskData.getTaskId());30 softAssert().isTrue(Strings.isNotNullAndNotEmpty(pickingTaskData.getTaskId()), desc + "taskId");31 softAssert().isTrue(pickingTaskData.getShopId() > 0, desc + "shopId");32 softAssert().isTrue(Strings.isNotNullAndNotEmpty(pickingTaskData.getTaskStatus()), desc + "taskStatus");33 softAssert().isTrue(Strings.isNotNullAndNotEmpty(pickingTaskData.getPointOfGiveAway()), desc + "pointOfGiveAway");34 softAssert().isTrue(Strings.isNotNullAndNotEmpty(pickingTaskData.getDateOfGiveAway().toString()), desc + "dateOfGiveAway");35 softAssert().isTrue(Strings.isNotNullAndNotEmpty(pickingTaskData.getPickingZone()), desc + "pickingZone");36 softAssert().isTrue(pickingTaskData.getDocumentVersion() > 0, desc + "documentVersion");37 softAssert().isTrue(pickingTaskData.getBuId() > 0, desc + "buId");38 softAssert().isTrue(Strings.isNotNullAndNotEmpty(pickingTaskData.getPriority()), desc + "priority");39 softAssert().isTrue(pickingTaskData.getProducts().size() > 0, desc + "products");40 }41 softAssert().verifyAll();42 }43}...
Source:Submit_APITest.java
...25 RequestSpecification httpRequest = getRequest("user_1", "pass_1");26 Response submitResponse = executeSubmitReq(httpRequest, groovyScript);27 SubmitEPResponse submitEPResponse = getGson().fromJson(submitResponse.asString(), SubmitEPResponse.class);28 Assert.assertEquals(submitResponse.getStatusCode(), 200, "User_1 is able to run the script");29 Assert.assertTrue(Strings.isNotNullAndNotEmpty(submitEPResponse.getId()));30 }31 /**32 * Method verify groovy/submit API is working as expected for simple string type33 * input34 *35 */36 @Test37 public void SubmitEPStringTest_Success() {38 String groovyScript = "'a+"+Math.random()+"'";39 RequestSpecification httpRequest = getRequest("user_1", "pass_1");40 Response submitResponse = executeSubmitReq(httpRequest, groovyScript);41 SubmitEPResponse submitEPResponse = getGson().fromJson(submitResponse.asString(), SubmitEPResponse.class);42 Assert.assertEquals(submitResponse.getStatusCode(), 200, "User_1 is able to run the script");43 Assert.assertTrue(Strings.isNotNullAndNotEmpty(submitEPResponse.getId()));44 }45 @AfterMethod46 public void afterMethod(ITestResult result) {47 printTestResults(result);48 }49}...
Source:Strings.java
...7 }8 public static boolean isNullOrEmpty(String string) {9 return string == null || string.trim().isEmpty();10 }11 public static boolean isNotNullAndNotEmpty(String string) {12 return ! (isNullOrEmpty(string));13 }14 /**15 * @param string - The input String.16 * @return - Returns an empty string if the input String is <code>null</code> (or) empty, else it returns17 * back the input string.18 */19 public static String getValueOrEmpty(String string) {20 return isNotNullAndNotEmpty(string) ? string : "";21 }22 private static final Map<String, String> ESCAPE_HTML_MAP = Maps.newLinkedHashMap();23 static {24 ESCAPE_HTML_MAP.put("&", "&");25 ESCAPE_HTML_MAP.put("<", "<");26 ESCAPE_HTML_MAP.put(">", ">");27 }28 public static String escapeHtml(String text) {29 String result = text;30 for (Map.Entry<String, String> entry : ESCAPE_HTML_MAP.entrySet()) {31 result = result.replace(entry.getKey(), entry.getValue());32 }33 return result;34 }...
isNotNullAndNotEmpty
Using AI Code Generation
1public void testIsNotNullAndNotEmpty() {2 assertTrue(Strings.isNotNullAndNotEmpty("foo"));3 assertFalse(Strings.isNotNullAndNotEmpty(""));4 assertFalse(Strings.isNotNullAndNotEmpty(null));5}6org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED7org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED8org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED9org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED10org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED11org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED12org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED13org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED14org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED15org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED16org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED17org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED18org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED19org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED20org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED21org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED22org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED23org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED24org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED25org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED26org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PASSED27org.testng.util.StringsTest > testIsNotNullAndNotEmpty() PAS
isNotNullAndNotEmpty
Using AI Code Generation
1import org.testng.annotations.Test;2import org.testng.util.Strings;3public class TestNGStrings {4 public void testIsNotNullAndNotEmpty() {5 String str = "Hello";6 System.out.println(Strings.isNotNullAndNotEmpty(str));7 }8}
isNotNullAndNotEmpty
Using AI Code Generation
1 [javac] if (Strings.isNotNullAndNotEmpty(schema)) {2 [javac] symbol: method isNotNullAndNotEmpty(String)3 [javac] if (Strings.isNotNullAndNotEmpty(schema)) {4 [javac] symbol: method isNotNullAndNotEmpty(String)5 [javac] if (Strings.isNotNullAndNotEmpty(schema)) {6 [javac] symbol: method isNotNullAndNotEmpty(String)7 [javac] if (Strings.isNotNullAndNotEmpty(schema)) {8 [javac] symbol: method isNotNullAndNotEmpty(String)9 [javac] if (Strings.isNotNullAndNotEmpty(schema)) {10 [javac] symbol: method isNotNullAndNotEmpty(String)
isNotNullAndNotEmpty
Using AI Code Generation
1import org.testng.util.Strings;2public class TestNGUtils {3public void testStringNotNullAndNotEmpty() {4 String testString = "test";5 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));6}7}8import org.testng.util.Strings;9public class TestNGUtils {10public void testStringNotNullAndNotEmpty() {11 String testString = "test";12 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));13}14}15package org.testng;16import org.testng.annotations.Test;17public class TestNGUtils {18public void testStringNotNullAndNotEmpty() {19 String testString = "test";20 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));21}22}23package org.testng;24import org.testng.annotations.Test;25public class TestNGUtils {26public void testStringNotNullAndNotEmpty() {27 String testString = "test";28 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));29}30}31package org.testng;32import org.testng.annotations.Test;33public class TestNGUtils {34public void testStringNotNullAndNotEmpty() {35 String testString = "test";36 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));37}38}39package org.testng;40import org.testng.annotations.Test;41public class TestNGUtils {42public void testStringNotNullAndNotEmpty() {43 String testString = "test";44 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));45}46}47package org.testng;48import org.testng.annotations.Test;49public class TestNGUtils {50public void testStringNotNullAndNotEmpty() {51 String testString = "test";52 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));53}54}55package org.testng;56import org.testng.annotations.Test;57public class TestNGUtils {58public void testStringNotNullAndNotEmpty() {59 String testString = "test";60 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));61}62}63package org.testng;64import org.testng.annotations.Test;65public class TestNGUtils {66public void testStringNotNullAndNotEmpty() {67 String testString = "test";68 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));69}70}71package org.testng;72import org.testng.annotations.Test;73public class TestNGUtils {74public void testStringNotNullAndNotEmpty() {75 String testString = "test";76 Assert.assertTrue(Strings.isNotNullAndNotEmpty(testString));77}78}
TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.
You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.
Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!