Skip to main content

Posts

javamail jdk11(11.0.10 and above) needs tls upgrade from 1.1 to 1.2

ISSUE 1: Unable to send/read mails using javamail/javaxmail after you upgraded your jdk to 11.0.10 or above?  The reason is they came up with higher security level for SSL with TLS 1.2 which is dependency for latest jdk, find the solution below: Possible Exception if you used older version TLS-1.1:  javax.net.ssl.sslhandshakeexception Solution: Add below property to your existing Properties. properties.put("mail.imaps.ssl.protocols","TLSv1.2");(IMAP used to read mail) properties.put("mail.smtp.ssl.protocols","TLSv1.2");(SMTP used to send mail) ISSUE 2: Unable to type case Multipart to String? From jdk11(latest version) onwards multipart and string cant be type casted, so we need to use Object to store message content. Solution: for (int i = 0; i < messages.length; i++) { Message message = messages[i]; Object content = message.getContent(); if (content instanceof String) { String body = (String)content; System.out.println...
Recent posts

How to invoke test for specific testng.xml using gradle

We know how to execute the whole set of test suite using gradle, here in this blog we show you how do we call specific set of tests with gradle which we have segregated tests based on multiple testng.xml files? Solution: Add below snippet at end of build.gradle file, we will define suites with project property function, and we will pass these suite objects to useTestNG function by validating user defined suite name with passed suite object. ===================================== def suite1=project.hasProperty("suite1") def suite2=project.hasProperty("suite2") def suite3=project.hasProperty("suite3") test {     testLogging {         exceptionFormat = 'full'         events = ["passed", "failed", "skipped"]         showStandardStreams = true     }     useTestNG() { /*This XML file is to execute first test suite*/     if(project.hasProperty("suite1")) {         suites "test...

Quick setup appium & launch play store app in connected android phone to automate app #java #appium

You can use eclipse or android-studio to create java project. To do this in Linux/ubuntu follow setps: Download Android SDK and store it in any specific dir. To open bashrc file to set env variables: vi ~/.bashrc In bashrc file save below & use source command to update: export ANDROID_HOME=/home/praveen/Android/Sdk export PATH=$JAVA_HOME/bin:$ANDROID_HOME/build-tools/29.0.3:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH Now save the bashrc file using "source ~/.bashrc" if you run "which aapt" we should see full path of aapt tool,this will confirm our android sdk evt variables are set correctly. Download eclipse, create new java project. download selenium standalone jar, download all selenium java jars & download appium java client jar & add all these as external jars using build-path for project into "class-path" which is very important. program: package androidapptest; import java.net.MalformedURLException; impo...

RestAssured rest API test framework for GET & POST API json verification with Extent report

package com.resttest; import static io.restassured.RestAssured.given; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.sql.DriverManager; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import org.apache.commons.collections.iterators.EntrySetMapIterator; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.json.JSONException; import org.json.JSONObject; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.AfterTest; import org.testn...

Adding Extent reporting for QA test automation framework

Define these globally: ExtentLoggerReporter logger = new ExtentLoggerReporter("/ebs/test/build/"); //The path given here will be used to store temp files for extent,create once. static ExtentReports extent; Define this method to initialise Extent configs before Test: @BeforeTest public void initialiseExtentReport() { logger.config().setAutoCreateRelativePathMedia(true); extent = new ExtentReports(); ExtentHtmlReporter html = new ExtentHtmlReporter("Extent.html"); extent.attachReporter(logger); extent.attachReporter(html); extent.loadConfig(new File(System.getProperty("user.dir")+"/extent-config.xml")); //extent-config.xml file content given below } For pom.xml add: <dependency>     <groupId>com.aventstack</groupId>     <artifactId>extentreports</artifactId>     <version>4.0.9</version> </dependency> On Our code, Wherever we are passing/failing the test step, we can use below c...

Extent report for Rest API test

Below code helps in failing or passing your Rest API test case & updating result to Extent report. Maven dependency(pom.xml): <dependency>     <groupId>com.aventstack</groupId>     <artifactId>extentreports</artifactId>     <version>4.0.9</version> </dependency> code: import com.aventstack.extentreports.ExtentReports; import com.aventstack.extentreports.reporter.ExtentHtmlReporter; import com.aventstack.extentreports.reporter.ExtentLoggerReporter; public class A{ ExtentLoggerReporter logger = new ExtentLoggerReporter("dir path to store extent result"); static ExtentReports extent; @Test public void testname(){ //Your code to capture json from get/post/put/delete API to "JSONObject jsonobjexpected" field. //your code to read actual json content from file/anywhere to "JSONObject jsonobjactual" field. try {         JSONAssert.assertEquals(jsonobjexpected.toString(...

How to execute linux command using java with printing output

There are two ways to execute linux commands in java, we illustrated both of them below, google to know difference between these. Below code is to print output of linux command to console using Runtime: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public static void executelinuxcommand(String linux_command) { StringBuilder output = new StringBuilder(); try { Process process = Runtime.getRuntime().exec(linux_command); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = reader.readLine()) != null) { output.append(line + "\n"); } int exitVal = process.waitFor(); if (exitVal == 0) { System.out.println("Linux command output :\n"+output.substring(0).toString()); } else { System.out.println("***** Linux command failed to execute"); } } catch (IOException e) { e.printStackTra...