Java Program for selenium interview

Reverse word in String using split function
Reverse every word in String using split function
Reverse a String using recrursion
Check a palindrome string
Find duplicate characters in String
Find vowels in a String
Find duplicate words in String
Count the number of words in a string?
Count the total number of occurrences of a given character in a string
Count oocurance of each character in a String
Check whether one string is a rotation of another?
Check two Stringa are anagram or not ?
Reverse a given string with preserving the position of spaces
Find the percentage of uppercase letters, lowercase letters, digits and special characters in a given string?
Find the longest substring without a duplicate character
Swap two Strings without using 3rd variable
Find first repeated and non-repeated character in String
Occurance of "that" word in a string like, AbthatCdthatjkthatggggthatth
print all permutations of String
find out longest palindrome in a given string

Rarely used locators - But very power full





ByChained locator helps to find the element based on the parent element, it accepts unlimited number of locators, Sequence is parent, child, grand child, great Grand child, target.

ByChained is normally used when its not possible to identify an element using one single attribute but you need to employ multiple attributes to identify it.

ByAll locator in selenium helps to find the element based on the given locators, locator could be any other types like id, name, classname, link text, xpath, css, partial link text.

ByAll locator tries to find the element using first locator if the element is not present then it waits for given implicit wait time, once it reaches the maximum wait time and if there is no element, ByAll method tries to find the element using second locator and goes on.

Finding element continues till it finds the element or there is no more locators

GIT Cheat Sheet


Thomson Reuters :- Selenium Interview Questions and answers

1.difference between list and set

List does can have repeat elements whereas set cannot have repeats. In list insertion order is not stored, whereas in set insertion order is maintained.

2. Write a program for fibinocis series

fibonacci series is easy.
int first = 0;
int second = 1;
SOP(first + " " + seconds + " ");
int next = 0;
for (int i = 0;i<num;i++)
{
next = first + second;
SOP(next);
first = second;
second = next;
}

3.he wrote some program we have to find which type of inheritence


4.difference between abstract class and interface

Abstract class is used when you know partial implementation whereas interface is when you dont know the complete implementation. In abstract class you need to have at least one abstract method whereas in interface all methods are abstract.


5.can we change public static like static public

Yes we can change

6.can we override main method

Main method can be overloaded and not override

7.what is constructor

Constructor is a method which is of the same name as a class. It is executed when an object of that class is created.

8. He gave one program which contain static and non static block and constructor. Write output

9. Lot of programs we have to write output

10.what is the latest version of selenium
selenium 3.9

11. What is difference between selenium 2 and 3

12.write a code set property for Firefox driver

 System.setProperty("webdriver.gecko.driver", "C:\\__path__");

13.what are methods available in action class

moveToElement, pressAndHold, contextClick, doubleClick

14.drag and drop selenium.

actions.clickAndHold(el1).moveToElement(e2).release(e2);

Python Day 01 Basic Introduction of Python




Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language.
  • Python is dynamic typed programming language.
  • Python is a platform independent language.
  • Python is interpreted programming language.
  • Python is freeware and Open Source language.
  • Python is extensible language.

  1. ·         Functional programming languages has been borrowed from c
  2. ·         Object oriented programming concept has been borrowed from c++.
  3. ·         Script programming language concept from shell & Perl
  4. ·         Modular programming language from Modula-3

Note: - 
  • Most of the syntax has been borrowed from C and ABC language.
  • In Python we have 30 keywords although in java we have 53.
  • In Python we will not require to specify the type of variable
  • Python new version i.e. 3 does not support Python 2  i.e. for old version


Flavors of python
  • ·         CPython :- used to work with C language
  • ·         Jython :- used to work with Java language
  • ·         JPython :- used to work with Java language
  • ·         IronPython :-
  • ·         Pypy :- Inside Python machine we have JIT compiler to improve the performance
  • ·         RubyPython:- used to work with Ruby language
  • ·         AnacondaPython:- used to work with big data or Hadoop
  • ·         Stackless :- used to work in multi-threading environment



Python Versions
  • ·         Python 1.0 introduced in Jan 1994 (Obsolete)
  • ·         Python 2.0 introduced in Oct 2000
  • ·         Python 3.0 introduced in Dec 2008
      • Python 3.6.3 is the latest version introduced in 2016.


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

Basic Syntax  :- Copy the below code and try to run the same you will get some idea

======================================================================
print("Hello Python")

a,b,c =10,20,40
print(a+b)

print(type(a))

a=True
print(type(a))

def f1(): print("good day")

f1()

for i in range(5):
    print(i)
    
x= 10 if c>b else 20
print(x)

def f2():
    print("let test another functions" ,x)
    f1();
f2()

import math
print(math.sqrt(4))

from random import *
print(randrange(0,100000))
for i in range(10):
    print(randint(0,9),randint(0,9),randint(0,9),randint(0,9),randint(0,9),randint(0,9),sep="")
    





Manual Testing Scenario Based Questions and Answers



Question :-

Suppose Amazon overtake Walmart but there is no merging of any content. Both will be working as two different websites at the front end but will be sharing a common backend process. Please specify the Test scenarios, plan and what kind of testing would you do.


Answer:-



1. As the backend of both e-commerce sites will be same, then the both sites user database should be one
2. User money transactions done in both sites should be reflected in one major account with detailed transactions details of every transaction.
3. The sellers who are tied up respective company there database needs to be maintained pretty well
4. When merged the backend of both, there should be no conflicts in user ids, we should also check the scenarios of users who are registered with both sites.
5. As the front end didn't changed, there should not be mix up in the front end products(as the backend is same, the products of respective sites should not be displayed in the other sites)
6. The promotional mails which will be sent to their respective registered users list should not get mixed(Amazon users should not get walmart mails and vice-versa)
7. If any offers Amazon is offering the same should not get affected or applied to walmart.
8. The money in their respective wallet should not get affected.
9. The respective apps must function same like before merge
10. When one site's changes are made and pushed to the server, the other site functionality should not get affected.
Etc etc


Question:-


Suppose you have a mobile application ready and working fine now client want to have a same application on the website having same functionality. How it will make you change in terms of testing. what are the things you will keep in mind and how will you make test plan of it.

can somebody help and give me the best answer of it.
Answer :-

1. First we should test the screen alignment in web application when accessed through browser

2. Security testing needs to be done from different browsers
3. Load and stress test needs to be done
4. Extra functionalities as per the req should be tested
5. User database should be verified
6. Compatibility with browsers needs to be tested
7. Screen resolution needs to be tested
8. Offline functionalities should be tested
9. Negative testing like while user browsing that webpage what if power goes off and internet goes off
10. Interruption testing like, while using that webpage receiving skype call, PC updates, antivirus updates etc...

java.lang.RuntimeException: java.net.BindException: Address already in use: bind- Resolved


Getting error message :- java.lang.RuntimeException: java.net.BindException: Address already in use: bind

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

now we need to kill this process to start again our test


E:\Selenium\2018_March\Hybrid.TestNG>netstat -ano | find "4444"
  TCP    0.0.0.0:4444           0.0.0.0:0              LISTENING       137924
  TCP    [::]:4444              [::]:0                 LISTENING       137924



E:\Selenium\2018_March\Hybrid.TestNG>taskkill -pid "137924" /f
SUCCESS: The process with PID 137924 has been terminated.

Link to download POI Jar files for selenium


Go to "https://poi.apache.org/download.html" page.

Select highlighted link present in the Binary Distribution section.


you can also download the previous version using link "
once download complete extract the folder and import the jar files in eclipse to read the excel file 


How to Generate Random String in Jmeter

Generate a random string using [A-Z,a-z,0-9]

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


For generating a random string length of 5 then use the below function

Name: randomstr5

${__RandomString(5,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,)}

For generating a random string length of 10 then use the below function

Name: randomstr10

${__RandomString(10,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,)}



What is meant by timers in Jmeter and why we use it

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

Timers are like adding some time in between different samplers, Like we can timers in non test element and after recording we can see that timers are auto added against each of the samplers.



Ways to perform headless browser Testing with chrome


What is headless Testing

Headless Testing means running a browser UI test without the head aka. no browser UI. It is extremely helpful when we don’t really care about the UI, but would like to execute out Automation tests as fast as possible and not involving any “draw” operations onto the screen that consumes it own time and memory.


Ways to execute headless browser Testing
1.        
If Chrome version is 59 we can use ChromeOption class as suggested below
ChromeOptions options = new ChromeOptions();
//Adding "headless" argument to options
options.addArguments("headless");
driver = new ChromeDriver(options);


if Chrome version is less than 59 we can use HtmlUnitDriver which allows us to select version of browser that you would like to run your tests on. You can select the browser version like this.





How to enable javascript support in Headless driver.


Can we pass more than one parameter in sendKeys() method



==========Selenium sendKeys Method ==============

public class Links {

public static void main(String[] args) throws Exception {

System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\selenium-java-3.5.0\\Browser Exe\\Chromedriver.exe");
WebDriver driver = new ChromeDriver();
//driver.manage().window().maximize();
driver.get("https://www.linkedin.com/");
driver.findElement(By.id("reg-firstname")).sendKeys("Test ", "Best ", "Rest ");
driver.close();
}
}

===================seendKeys() Method with parameter =========================



====================Explanation ================

 CharSequence represents an interface to a sequence of characters, with operations common to all classes implementing it. Mutability is not enforced by this interface, So, you can have an immutable implementing class, like String or mutable ones, like StringBuilder and StringBuffer.

Since CharSequence  is the parent interface for all these class thus we can cast all the sub classes into this type. so this is the reason behind accepting the Sting, so when we pass the string it will e automatically upcasted in to CharSequence.

and  ... (three dots) in Java known as "ellipsis", now varrags allows the method to accept zero or muliple arguments. Before varargs either we use overloaded method or take an array as the method parameter but it was not considered good because it leads to the maintenance problem. If we don't know how many argument we will have to pass in the method, varargs is the better approach.

Always remember "Varargs" stands for Variable Argument .

The varargs uses ellipsis i.e. three dots after the data type. Syntax is as follows:

return_type method_name(data_type... variableName){}

org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary - While Running Through Jenkins

[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ Maven.Final ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 32967
Only local connections are allowed.
FAILED CONFIGURATION: @BeforeClass setUp
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 54 milliseconds
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:01:39.354Z'
System info: host: 'XXXXXXXXXX', ip: 'XXXXXXXXXXX', os.name: 'Windows 10', os.arch: 'XXXXXX', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: ChromeDriver
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)


Let see how to resolve this problem, if we run our project through intellj or eclipse using TestNG or Maven our Script will work fine but when we try to run this using Jenkins the Jenkins could not access the binary from our system, since It is possible that chrome is installed on your AppData folder in C drive, so we need to be sure that jenkins is able to access our chrome binary file.


Now to access the binary file we need to add below snippet


ChromeOptions chromeOptions= new ChromeOptions();
chromeOptions.setBinary("C:\\Users\\Manish\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
 System.setProperty("webdriver.chrome.driver","C:\\Users\\manish\\Downloads\\chromedriver_win32\\chromedriver.exe");
 driver = new ChromeDriver(chromeOptions);


i hope this resolve your problem let me know if this won't work for you guys.

Selenium Interview Questions and Answers

Selenium Interview Questions 


What is WebDriver?

What are the methods Present in the WebDriver interface?

What is the difference between get() and navigate.to() Method ?

WebDriver driver = new FirefoxDriver(); How does it work?

What are the reasons we don’t write “FirefoxDriver driver = new FirefoxDriver();”.

Do we have another way to enter text in to the text box without sendKeys() function?

Is WebElement is interface or a class?

What are the methods present in the WebElement interface ?

What is the return type of navigate method ?

Explain navigate().to() function. ?

How to find the count of total number of input box on the page ?

How to print the text present on the button ?

How to find the total number of buttons present on the page ?

How to find the width and height of the button ?

What error message would return if we pass wrong xpath expression?

How to find the x and Y coordinates for any web Element in selenium.

How to get typed text from a textbox ?

What is the super interface of Selenium ?

What all methods are present in super interface of selenium?

What are the different ways to click on the link?

How to find all the links present on the page?

How to find all the hidden links present on the page ?

How to find all the broken links present on the page ?

Explain list interface in java Collections ?

How to get the index of the object present in the list?

What is the difference between findElement and findElements?

What exception will you get if you don’t find any element on the page using findElement and findElements?

How to click all the links present on the page one by one ?

How to click on the hidden link present on the page ?

Difference between List and Set Interface ?

What is meant by ArraryList is not synchronized ?

Explain IsDisplayed method in Selenium ?

What is Random class in java?

Write a program for below mention scenario.

·         Let say we have 50 links on the page and every time I run the test I wanted to click a link randomly 

Write a program to find total number of radio button on the page ?

WAP to find selected radio button for rediff sign-up page ?

Create a function to get all the links present on the page.

Create a function to get list of all the visible links.

Create a function to get the list of link present in a specific div.

Create a function to click on the link based on user inputs.

Create a function which will click on any random link. (Random Class)

Create a function to get the herf attribute value of the links.

Create a function to select dropdown value using sendkeys function.

Create a function to select any value from dropdown using Select class.

Create a function to get the list of all the dropdown values.

Create a function to get the text of selected element present in the dropdown.

Create a function to get count of window instances.

Create a function to get count of frames present on the page.

Create a function to switch on desired window and close that pop-up window.

Create a function to check in Alert is present.

Create a function to get the text of alert and close the same.

Create a function to switch on the desired frame.

Which function we used to get back from frame to window.

Suppose we have two frames on a page 1 want to click ok button which is present on first frame and then would like to click on refresh button which Is present on the second frame write a code for the same.

What is the difference between quit and close function.

How to handle light boxes in selenium for reference use Flipkart login.

How to handle Java Alert

Create a custom function having return type as webElement based on any locator.

Create function to hover and click.

Create a program to use draganddrop functionality

Create a function to take the screenshots

Create a function to scroll down.

Create a function to scroll at a particular  element

Create a function to simulate right click of mouse

Create a function to store all the values for a particular column ?

Create a function to store all the values for a particular Row ?

What is meant by locators list out all the locator Names?

Create a OpenApplication function which include implicit wait as well as PageTimeOut.

What is the difference between Implicit wait and explicit wait?

ExpectedConditions  is a class or a interface ?

How to get the path till current working directory.

How to handle window based pop-up.

========================================================================
Question  :- What is the full form for ANT and POI ?

Answers :-  POI stands for :- “Poor Obfuscation Implementation” and Ant Stands for “Another Neat Tool”.

=======================================================================
Question :-  How do you Achieve Parallel execution In TestNG ?

Answers :- To run our test cases i.e methods or classes parallelly  using testNG we need to use Parallel attribute in TESTNG.xml file also need to specify how many instances you want to open in one go for parallel execution and this can be achieved via thread count attribute in TestNG.xm file.

Note:- parallel and thread-count attribute should always be defined at suite level.


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

Question :- How to run failed test cases only using TestNG.

Answer:- To execute only failed tests we have provision in the TestNg. After completion of the suite execution; just refresh the project folder then you can find a folder called “test-output” and there you can find an xml file called “testng-failed.xml”. This xml file contains only failed test cases. So, we can execute this xml file to rerun the failed test again.

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

Question :- How to rerun the failed test cases in TestNG with in the execution mode.

Answers :- we can execute failed test cases using TestNG in Selenium –By Implementing TestNG IRetryAnalyzer.


=======================================================================
Question :- What is CharSequence in Sendkeys?

Answer :- CharSequence represents an interface to a sequence of characters, with operations common to all classes implementing it. Mutability is not enforced by this interface, So, you can have an immutable implementing class, like String or mutable ones, like StringBuilder and StringBuffer.

Since CharSequence  is the parent interface for all these class thus we can cast all the sub classes into this type. so this is the reason behind accepting the Sting, so when we pass the string it will e automatically upcasted in to CharSequence.

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

Question :- Did you noticed that we have ... (three dots) with CharSequence present under sendKeys what does they signify ?

Answer :- These ... (three dots) in Java known as "ellipsis", now varrags allows the method to accept zero or muliple arguments. Before varargs either we use overloaded method or take an array as the method parameter but it was not considered good because it leads to the maintenance problem. If we don't know how many argument we will have to pass in the method, varargs is the better approach.

Always remember "Varargs" stands for Variable Argument .

The varargs uses ellipsis i.e. three dots after the data type. Syntax is as follows:

return_type method_name(data_type... variableName){}

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

Question : Can we pass more than one parameter in sendKeys() method.

Answer :- Yes we can, then reason is sendKeys method defines as below.

public String sendKeys(CharSequence ... args0)
{
}

Example  :- here

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

Question :- How to test the change in color of any hyper link after hovering the link by using selenium.

Answer :- we can use method .GetCSSValue("color") on a webElement to get its color value.

Example :-

 String headerColor = driver.findElement(By.xpath(".//*[@id='LoginName']/h1")).getCssValue("Color");
   Assert.assertEquals("some message", "#EEEEEE", Color);

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