Sunday, February 13, 2022

Q) How To Find Duplicate Characters In A String In Java?

Step1:- Creating a HashMap containing char as key and it's occurrences as value.


Step2:- Converting given string to char array.


Step3:- checking each char of strArray.


Step4:- If char is present in charCountMap, incrementing it's count by 1.


Step5:- If char is not present in charCountMap,

     putting this char to charCountMap with 1 as it's value.


Step6:- Getting a Set containing all keys of charCountMap.

Step7:- Iterating through Set 'charsInString‘

Step8:- If any char has a count of more than 1, printing it's count 

=========================================================================

package com.interviewprogramcomm;


import java.util.HashMap;

import java.util.Set;


public class FindCharCountInStr {

public static void findcharcountInStr(String str){

HashMap<Character,Integer> hm=new HashMap<Character,Integer>();

char[] c=str.toCharArray();

for(char c1:c){

if(hm.containsKey(c1)){

hm.put(c1,hm.get(c1)+1);

}

else{

hm.put(c1,1);

}

}

Set<Character>  set=  hm.keySet();

for(Character c2:set){

if(hm.get(c2)>1){

System.out.println(c2+"::"+ hm.get(c2));

}

}

}

public static void main(String[] args) {

findcharcountInStr("javajavaM");


}


}

=========================================================================



Saturday, December 18, 2021

Screen Shot for Pass and Failed Test Cases

 Step1:- Create Maven Project 

Step2:- Add below dependencies

<dependency>

              <groupId>com.relevantcodes</groupId>

              <artifactId>extentreports</artifactId>

              <version>2.41.2</version>

          </dependency>

          <dependency>

              <groupId>org.testng</groupId>

              <artifactId>testng</artifactId>

              <version>6.14.3</version>

              <scope>test</scope>

          </dependency>

          <dependency>

              <groupId>org.seleniumhq.selenium</groupId>

              <artifactId>selenium-java</artifactId>

              <version>3.141.59</version>

          </dependency>

 

          <dependency>

              <groupId>org.apache.poi</groupId>

              <artifactId>poi</artifactId>

              <version>4.1.1</version>

          </dependency>

          <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->

          <dependency>

              <groupId>org.apache.poi</groupId>

              <artifactId>poi-ooxml</artifactId>

              <version>4.1.1</version>

          </dependency>

          <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->

          <dependency>

              <groupId>commons-io</groupId>

              <artifactId>commons-io</artifactId>

              <version>2.6</version>

          </dependency>

          <dependency>

              <groupId>org.apache.logging.log4j</groupId>

              <artifactId>log4j-api</artifactId>

              <version>2.16.0</version>

          </dependency>

          <dependency>

              <groupId>org.apache.logging.log4j</groupId>

              <artifactId>log4j-core</artifactId>

              <version>2.16.0</version>

          </dependency>

 Step3:-  Create Base Class 

package ExtendReport.ExtendReport;

 

import java.io.File;

import java.io.IOException;

 

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class Base {

       public static  WebDriver driver;

      

       public void initialization(){

                   

                                                System.setProperty("webdriver.chrome.driver","F:\\drivernew123\\chromedriver.exe");

                                                driver=new ChromeDriver();

                                                driver.get("https://www.google.com/");

               

       }

      

       public void failed(String testMethodName) {

                   File scrFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

                   try {

                                                //FileUtils.copyFile( scrFile, new File("E:\\Seleniumbatch\\ExtendReport\\ScreenShot\\testFailure.jpg"));

                                   FileUtils.copyFile( scrFile, new File("E:\\Seleniumbatch\\ExtendReport\\ScreenShot\\"+testMethodName+"_"+".jpg"));

                                   

                                   

                                   

                                } catch (IOException e) {

                                                // TODO Auto-generated catch block

                                                e.printStackTrace();

                                }

       }

      

      

      

}


Step3:- Create CustomListernerClass

package ExtendReport.ExtendReport;

 

import org.testng.ITestContext;

import org.testng.ITestListener;

import org.testng.ITestResult;

 

public class CustomListener extends Base implements   ITestListener{ {

 

}

 

public void onTestStart(ITestResult result) {

                // TODO Auto-generated method stub

 

}

 

public void onTestSuccess(ITestResult result) {

                System.out.println("SuccessTest");

                failed(result.getMethod().getMethodName());

 

}

 

public void onTestFailure(ITestResult result) {

                System.out.println("Faied Test");

                failed(result.getMethod().getMethodName());

 

 

}

 

public void onTestSkipped(ITestResult result) {

                // TODO Auto-generated method stub

 

}

 

public void onTestFailedButWithinSuccessPercentage(ITestResult result) {

                // TODO Auto-generated method stub

 

}

 

public void onStart(ITestContext context) {

                // TODO Auto-generated method stub

 

}

 

public void onFinish(ITestContext context) {

                // TODO Auto-generated method stub

 

}

 

 

}

Step4:- Create ScreenShotFailuarclass

package ExtendReport.ExtendReport;

 

import org.openqa.selenium.By;

import org.testng.Assert;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

 

@Listeners(CustomListener.class)

public class ScreenShotFailuar extends Base{

               

                @BeforeMethod

                public void setUp(){

                                initialization();

                }

               

                @AfterMethod

                public void tearDown(){

                                //driver.quit();

                }

               

                @Test

                public void takeScreenShot1(){

                                Assert.assertEquals(false,true);

                }

                @Test

                public void takeScreenShot2(){

                                Assert.assertEquals(false,true);

                }

                @Test

                public void takeScreenShot3(){

                                Assert.assertEquals(false,true);

                }

                @Test

                public void takeScreenShot4(){

                                String actualStr=driver.getTitle();

                                System.out.println(actualStr);

                                Assert.assertEquals(true,true);

                                driver.findElement(By.name("q")).sendKeys("IngeniousTechHub");

                }

               

                @Test

                public void takeScreenShot5(){

                                Assert.assertEquals(true,true);

                }

               

               }

Below is the Output



               

 

} 

Screen Shot for Failure & Pass Test Cases With Extent Report

Step1:- Create Maven Project.

Step2:- Add Dependency


<dependency>

              <groupId>com.relevantcodes</groupId>

              <artifactId>extentreports</artifactId>

              <version>2.41.2</version>

          </dependency>

          <dependency>

              <groupId>org.testng</groupId>

              <artifactId>testng</artifactId>

              <version>6.14.3</version>

              <scope>test</scope>

          </dependency>

          <dependency>

              <groupId>org.seleniumhq.selenium</groupId>

              <artifactId>selenium-java</artifactId>

              <version>3.141.59</version>

          </dependency>

     

      <dependency>

              <groupId>commons-io</groupId>

              <artifactId>commons-io</artifactId>

              <version>2.6</version>

          </dependency>

    =========================================================

Step3:- Write Below code








=========================================================================
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import javax.swing.plaf.FileChooserUI;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class AmazonTest {
public WebDriver driver;
public ExtentReports extent;
public ExtentTest extentTest;

@BeforeTest
public void setExtent(){
extent=new  ExtentReports(System.getProperty("user.dir")+"/test-output/ExtentReport.html",true);
extent.addSystemInfo("Host Name","Mohit Window");
extent.addSystemInfo("UserName","Mohit Kumar");
extent.addSystemInfo("Environment","QA");

}

@AfterTest
public void endReport(){
extent.flush();
extent.close();
}

public static String getScreenShot(WebDriver driver,String screenShotName) throws IOException{
String dateName=new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
TakesScreenshot ts= (TakesScreenshot)driver;
File sources=ts.getScreenshotAs(OutputType.FILE);
String destination= System.getProperty("user.dir") + "//FailedTestsScreenshots//" + screenShotName + dateName
+ ".png";
File fileDestination=new File(destination);
FileUtils.copyFile(sources, fileDestination);
return destination;
}



@BeforeMethod
public void setUp(){
System.setProperty("webdriver.chrome.driver","F:\\drivernew123\\chromedriver.exe");
driver=new ChromeDriver();

driver.get("https://ingenioustechhub.blogspot.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}


@Test
public void verifyTitle(){
extentTest=extent.startTest("verifyTitle");
String actual=driver.getTitle();
Assert.assertEquals(actual,"asasdasd");
}

@Test
public void verifyTitleOfpage(){
extentTest=extent.startTest("verifyTitle");
String actual=driver.getTitle();
Assert.assertEquals(actual,"Ingenious TechHub");
}

@AfterMethod
public void tearDown(ITestResult result) throws IOException{
if(result.getStatus()==ITestResult.FAILURE){
extentTest.log(LogStatus.FAIL,"TEST CASE FAILED IS "+result.getName());//to add name in extent report
extentTest.log(LogStatus.FAIL,"TEST CASE FAILED IS "+result.getThrowable());//to add error/exception in extent report
String screenshotPath=AmazonTest.getScreenShot(driver,result.getName());
extentTest.log(LogStatus.FAIL, extentTest.addScreenCapture(screenshotPath));//to add screenshot in extent report
//extentTest.log(LogStatus.FAIL, extentTest.addScreencast(screenshotPath));//to add screenshot in extent report

}
else if(result.getStatus()==ITestResult.SKIP){
extentTest.log(LogStatus.SKIP,"Test Case SKIPPED IS " + result.getName());
}
else if(result.getStatus()==ITestResult.SUCCESS){
String screenshotPath=AmazonTest.getScreenShot(driver,result.getName());
extentTest.log(LogStatus.PASS, extentTest.addScreenCapture(screenshotPath));
}
extent.endTest(extentTest);//Ending test and ends the current test and prepare to create html report

driver.quit();
}

}
=========================================================================
















Monday, November 1, 2021

SQL Practice

CREATE TABLE TEST(SNO NUMBER(10));

INSERT INTO TEST values(1);

SELECT * FROM TEST;

=======================

Q)WAQ to find the duplicate name in table.

create table user1 (Id VARCHAR(20) primary key,

name VARCHAR(30), Emailid VARCHAR(30),age INTEGER);

select * from user1;


INSERT INTO user1 VALUES('O1201', 'Radhika Malhotra', 'rad12@gmail.com', 21); 

INSERT INTO user1 VALUES('O1202', 'Aryan Ray', 'Ar13@gmail.com', 25); 

INSERT INTO user1 VALUES('O1203', 'Sam Das', 'Sam1@gmail.com', 54); 

INSERT INTO user1 VALUES('O1204', 'Radhika Malhotra', 'rad12@gmail.com', 21);

INSERT INTO user1 VALUES('O1205', 'Aryan Ray', 'Ar13@gmail.com', 25);

INSERT INTO user1 VALUES('O1206', 'Radhika Malhotra', 'rad12@gmail.com', 21);   


Select name,count(*) As Occurrence FROM

user1 Group By Name having Count(*)>1;


Sunday, October 31, 2021

ITC Infotech Interview Question for Automation Test engineer (2 to 5 year Experience 2021)

 1) Tell me about skills, roles , responsibilities and experience ?

2) What Singleton class in java can you write code ?

3) WAP to count each occurrence of words in Sentence ?

4) What is steal Element exception in selenium ?

5) What is finally block in java ?

6) What is hooks in cucumber ?

7) What is difference between selenium and cucumber ?

8) Can you explain your Rest assured framework ?

9) How to authenticate POST method ?

10) What is Hash Map and Hash Tree ?

11) where you have used collection in your project ?

DBS Interview Question for Automation Test engineer (2 to 5 year Experience 2021)

 1) Tell me About your roles and responsibilities in your current projects. 

2) What is interface and abstract class 

3) How to handle Alert 

4) Write code for Screenshot . 

5) write a code to find duplicate in Array and display each  occurrence . 

6) What is difference between close  and quit method

7) Can you tell 5 exception in selenium. 

8) Write queries for max sal 5 salary for emp

9) Can you explain your framework

10) How create jobs in Jenkins

11) How to schedule job in Jenkins


ADP Interview Question for Automation Test engineer (2 to 5 year Experience 2021)

 1) Tell me about your self

2) What is locator and types of locations

3) Given to write Xpath using I'd locator 

4) WAP to find duplicate character in String. 

5) What is overriding and overloading in java and WAP for overriding and overloading. 

6) What is wait statements in selenium? 

7) Have you developed framework. 

8) What is method hiding

9) WAP to reverse each character in string.

Q) How To Find Duplicate Characters In A String In Java?

Step1:- Creating a HashMap containing char as key and it's occurrences as value. Step2:- Converting given string to char array. Step3:- ...