Total Pageviews

Thursday, 27 September 2018

Interview Questions


1> How will you compare two excel sheets, cell by cell using apache poi
2> Question on random number generation between two limits
3> Can we make post request using get in restful
4> Difference between vi and view in linux
5> What is sed in linux
6> Difference between page object and page factory in selenium


Version Control Systems are just that, software that provides versioning functionality (Git, Subversion, TFS Version Control) all fall into this category.

Software Configuration Management is a broader term that encompasses all the processes needed to build, package, and deploy software -- this includes Version Control Systems. It does not refer to software per se.

Jenkins is a CI tool means Continuous Integration tool. It can also be used as a CD i.e. Continuous deployment tool using Deleivery Pipeline Plugin.

In Continuous Integration, every code commit is build and tested, but, is not in a condition to be released on production servers for UAT.

In Continuous Delivery, the application is continuously deployed on the production servers for UAT Or we can say the application is ready to be released to production anytime.


/*****************************************************************************/

Ques: Explain error :



Ans: Lets first understand how default constructors are created . If you dont declare a constructor in a class then compiler by default creates a constructor like this:

Class dummy extends dummy2{
          dummy(){
              super();
          }
}


So we get this error because a class which has no constructor, for those classes compiler automatically creates a default argument less constructor.

Since here our parent class test has been given a parameterized constructor and if we do not declare constructor in child class then by default constructor should create default constructor like above but here compiler wont know how to handle arguments in super keyword. Thats why it is asking us to define constructor.

So it can be handled in two ways like below.:
Way 1:  





Way2:


Ques.2> Reverse arr 1,2,3,4,5  to 5,4,3,2,1
Ans:

Ques3> Reverse this in this way:
 This Is India      ->  sihT sI aidnI


/*****************************************************************************/

Ques:Why can't static method access 'this' or 'super' in Java?

Ans: A static method belong to class rather than object of class. Now this keyword is a refrence variable which is used to refer current class object. Same way super keyword is a reference variable which is used to refer immediate parent class object.
So we can say this and super keywords both are reference variables that refers to some variable.
In othere words we can say these both keywords belongs to instance of class.

Whereas, static method belong to class rather than instance of class.

That's Why static method cant access this and super keyword in java.

Ques: What are recovery scenarios in QTP?

Ques: Different type of constructors.

Ques: How do you run Sahi from jenkins/cmd.
Ans:  From Jenkins
Step:1 First create ant target using sahi editor and save it by name build.xml
Step:2 In build.xml in scriptDir node pass the path where your scripts directories are kept
Step:3 In jenkins configure new job and in build step pass this build.xml path

From cmd
To run sahi suite from cmd prompt go to test runner folder and fire command in this way:
C:\sahi_pro\userdata\bin> testrunner <sahifile/suitefilename> <starturl> <browserType> <tags>

Q: Sahi Pro parallel Execution.
Ans: To run tests parallely using sahi pro on a single machine create a suite file with testcases names in it and from sahi pro editor window open run as and select number of threads and types of browsers to run. Then run.

Ques. How to run sahi scripts on multiple machines.
Ans : Sahi Pro can distribute and run tests on multiple machines (nodes).
drun.bat(windows) and drun.sh(linux) files allow running scripts on multiple machines from the command line.

Open sahi_pro/userdata/bin/drun.bat (drun.sh on linux) using any editor.
Configure the NODES variable to contain all the machines on which the tests should run. The command to set the nodes in Windows
For Windows:
SET NODES=localhost:9999;othermachine:9999;thirdmachine:9999

Now trigger from cmd prompt
c:\sahi_pro\userdata\bin>drun demo.suite http://www.testingsite.com/ chrome+ie+firefox

For more details refer to sahipro documentation site

Ques: What is @Factory in testNG? / How to run parallel instances in testNG? / What is the meaning of running parallel instances in testNG? / How to use dataprovider which is in different class?

Ans:
--@Factory annotation marks method as a factory that returns objects that will be used by TestNG as test classes.
--In testNG xml, for parallel execution in parallel tag we can give classes, methods or instances. If we specify instances in testNG xml then testng will create different instances
   of classes per thread and run in that particular thread.
--running parallel instances means running parallel instances of classes in TestNG and parallel instances attribute is applicable in the case of factories that are powered by a data provider and when set would cause the instances produced by a factory to run in parallel



Ques: default and static method in Java8. Which method will be called if two interfaces having same name default method is implemented by a class.

Ans:



Ques: build.gradle
Ans:

Ques: How to convert Maven based Java Project to support Eclipse IDE?
Ans:
Step1: Navigate to your java project folder where pom.xml is present and fire this command:
           mvn eclipse:eclipse
Step2: Now you will notice that two new files are created i.e. .classpath and .project ,both the files are created for eclipse ide.
In .classpath file we will have a variable m2_repo, we will have to add this on our build path. m2repo is a variable that defines where maven 2 repository is on our disk.
Step3: Now you can import it in eclipse.


Ques: What maven clean does.
Ans: cleans up artifacts created by prior builds.

Ques: What does .class file contains in Java
Ans: It contains bytecode.

Ques: What does .mvc and .project file contains?
Ans: 


Ques: What is pipeline in jenkins?
Ans: Jenkins pipeline is a suite of plugins which supports implementing and integrating continuous delivery pipeline into jenkins.continuous delivery (CD) pipeline is an automated expression of your process for getting software from version control right through to your users and customers.

Ques: What are default overloded methods in jenkins?
Ans: 



Ques: Example where we override some method in java/selenium
Ans: We override apply method of function interface.

Function<WebDriver,Boolean> func = new Function<WebDriver,Boolean>() {

@Override
public Boolean apply(WebDriver arg0) {
// TODO Auto-generated method stub
return null;
}
};

Ques: What is staleelement exception and how do you handle it.
Ans: We get stalelementexception when the element is no longer attached to dom or its references has been changed. This can occur due to navigating back , refreshing page or some ajax section got refreshed.
Example to get this exception:


To solve this :
1> After weblements are initialized, do not refresh the page. If situation comes that page gets refreshed then initialise elements again.
2>We could avoid StaleElementException using POM. In POM, we use initElements() method which loads the element but it won’t initialize elements. initElements() takes latest address. It initializes during run time when we try to perform any action on an element. This process is also known as Lazy Initialization.
3>Other ways are to use explicit waits to wait for element to attach itself to dom in case of Ajax.
Ques: Handling exceptions in testNG?
Ans: 


Ques: How to resolve git merge conflicts?
Ans.
Conflict comes when you are trying to push changes on remote server where already some one has meade changes like below:

Step 1: fire command
git pull --rebase origin master

Step3: fire command  git am --show-current-patch  ,to see the issue

Step4: fir cmd   git mergetool


Now press i and edit the file like you do in linux then save all 4 instanses e.g. :wq and press enter 4 times.

Step 5: fire command   git rebase --continue
Step 6: fire command  git push origin master



##origin is a term for the remote repository and master is the branch there.
##If we don’t mention any priority, testng will execute the @Test methods based on alphabetical order of their method names irrespective of their place of implementation in the code


Ques.:  When do u get this error:
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.

Ans.: This issue comes when webdriver is of lower version and browser is of higher version and because of this they have got difficulty talking to each other.


Ques: Steps to configure jenkins for maven Project.
Ans.:  Configuring jenkins for maven project
1: Download jenkins war file
2: Create a folder for jenkins and paste above war file in there
3: Now open cmd and gotot dir where u have kept this war file and fire command jave -jar <give war file name>
4: Once done launch browser and fire url: localhost:8080 and copy password for command prompt and paste it there..
5: Install suggested plugins
6: If maven plugin not available then install it from manage page of jenkins
7: Click on new item and give your project name then select maven project
8: In source code mangement chhose repository where ur code is available like git/subversive or local
9: Give your projects pom.xml file path
10: In goal and options give - clean install  , so maven will first claean and install and then run
11: Click on build now. (We can do many othere things also like scheduling build,triggereing build whenever there is checkin in repository,after execution sending mails to different persons etc.)


Ques.: How do you implement log4J in your project?
Ans.: Log is capturing the information which goes on at the time of execution.
Types of logs
1>info
2>warn
3>error
4>fatal
To generate logs we can use apache log4j api
How it works: it reads log4j configuration from log4j.properties file
Where to create properties file? --create inside resources folder, name it exactly as log4j.properties and in this file give information in the form of key and value pairs

Create object like below in class and use
Logger log = Logger.getLogger(LoginPageTest.class);  Here LoginPageTest is the name of the class in which we are creating Logger object.






/*****************************************************************************/

















JAVASCRIPT

1> Difference between var and let in javascript

--- var is scoped to the nearest function block while let is enclosed to the nearest enclosing block.
     
 
--- Both are global if outside any block.

const statement values can be assigned once and they cannot be reassigned. 
example:
function nodeSimplified(){
  const MY_VARIABLE =10;
  console.log(MY_VARIABLE);  //output 10
  MY_VARIABLE =20;           //throws type error
  console.log(MY_VARIABLE); 
}

2> Difference between == and ===
Ans: == just compares value while === compares value and type both.

3> what is the difference between "undefined" and "null" keywords?
--- undefined means variable has been declared but has not been assigned a value. 
While null can be assigned to variable representing no value.

null === undefined // false
null == undefined // true

if we do typeof undefined it gives undefined while if we do typeof null it gives object.

Q.what is use of Arrow function?
Ans.




















CUCUMBER

TestNG frame work is TDD , test driven development immediately we write code but in BDD we write code along with business logic

Advantage with BDD is that u can write features immediately and code part we can take up later.
In BDD frame work any one can contribute in writing the features. Business Analyst or Manual Tester or any one from agile team can write feature file and automation tester can write
code based on that feature file.

Disadvantage: We have to write too much, In testNG we dont have to write this much just right @test,@aftermethod etc


Keywords in Cucumber:

Feature: It defines logical test functionality you will test in feature file. example:
               Feature: LogIn Action Test

Background: This keyword is used to define steps which are common to all scenarios in feature file. example:
     Background: User is logged in
          Given: user on login page
          When: User enter creds iand enters
          Then: home page displayed

Now the given when then inside background will be repeated before every scenario

Scenario: Each feature will contain some number of test to be tested. Each test is called scenario and each scenario will be followed by given,when,then steps.

Scenario Outline: Some scenarios can be executed for multiple set of data using scenario outline.  Data provided by tabular structure separated by |

Given: Defines precondition of test
When: It defines the test action which will be executed
Then: Keyword defines outcome of previous step. We define post condition with then
And: And keyword is used to add conditions to step  example :
          When : user navigate to login page
   And : user enters username and password

But: But keyword is used for negative testing example:
        Given User is on Home Page
        When User Navigate to LogIn Page
        And User enters UserName and Password
        But The user credentials are wrong
        Then Message displayed Wrong UserName & Password


*: Star keyword defies whole purpose of given when then, just use * in place of given , when , then and test will still work fine


Feature File: Features file contain high level description of the Test Scenarios in simple language. Language is known as Gherkin.

StepDefinition file: StepDefinition File maps test case steps in feature file with methods.


Cucumber Options:




  • Parameterization without Example Keyword



Parameterization with Example Keyword:





Parameterization Using Tables:












Use of Tags:





Hooks:
There are two types of hooks in cucumber. @before and @after, which are executed before and after scenarios.

@Before(order = int) : This runs in increment order, means value 0 would run first and 1 would be after 0

So just Define @before and @after in stepdefinition file , and at the time of execution these will be executed before and after scenario


BackGround Vs Hooks:
Background in Cucumber is used to define a step or series of steps which are common to all the tests in the particular feature file.
So if you have mentioned background in a feature file then it will run before every scenario for that particular feature file.
while suppose you have mentioned hooks with @before annotation the it is going to run before all scenarios of all the feature files which u are running.

The background is run before each of your scenarios but after any of your @Before hook.

Any feature level dependency should be tie with the background and any scenario level dependency should be tie with hooks.

It is a good practice to keep the background short.







Wednesday, 5 September 2018

API Automation



  • Used jayway restassured to automate api



  1. Get: get is used to fetch the data 
  2. Post:In post we are adding new entry
  3. Put: In Put we are updating entry, if in put u are sending only entry (in body) which needs to be updated then it is going to update that entry and will remove others so to overcome this we use patch
  4. Patch: Patch is used just to update data. With patch we only send data in body which needs upfation
  5. Delete: It removes record
-- Get is the read only method whereas put , post and delete are write methods.
-- Get,Put and Delete are idempotent, we can safely repeat them as many times but post is non                idempotent and we should not repeat it. We can understand it this way suppose we accessed a webpage then we can without any problem refresh it.Its a get request for server but suppose we are filling a form and after filling if we try to refresh the browser will warn us saying u have already submitted , r u sure ..? like this 'cause this will be a duplicate request for browser.









Options Method: gives us details of allowed method, which all methods server accepts

SOAP: Simple object access protocol and it can interact with other programming language applications(means language and plateform independent)

Advantages:
--It has its own security known as WS Security
--Language and plateform independent

Disadvantages:
1-It supports only xml format and it is slow because it has to follow many standards
2-It works with WSDL(Web Service Description Language and its written only in form of xml) file only , no othere formats like json is accepted

Restful Webservices
It stands for Representational State Transfer
It is plateform dependent
It supports multiple formats like json,text,html,xml etc
It is fast as compared to soap
It is an architectural design not protocol like soap

Responce codes
1XX--info
2XX--success
3XX--redirection
4XX--client error
5XX--server error



Refrence is : https://www.youtube.com/watch?v=-W41NVeb7UM&index=2&list=PLmfZ8pjwM0vTVzGG5v0CrWxJaeHPP1KvH



Tuesday, 4 September 2018

Programs

1> Find difference between two dates:

here we are dividing by 1000 to get diff in seconds otherwise without dividing we would have got difference in milli seconds



2> Find list of all working links on a single webpage

3> Find list of all working links in whole website
-- we will be using concept of crawling whole website using jsoup and recursion.


4> How do you fire commands in Java.


5> Which is given more priority, priority or depends on method

6> Maven Plugins



7> TestNG Parallel attributes







8> count number of times a number is present in array like Integer[] arrr = {1,3,6,1,3,7,9,6,3,1]