1st Round : Technical
Duration : 45 mins
Total Questions : 17
1. what is static and runtime polymorphism.
Ans: Static/compile time polymorphism:
Polymorphism
that is resolved during compiler time is known as static polymorphism. Method
overloading is an example of compile time polymorphism.
Method
Overloading:
This allows us to have more than one method having the same name, if the
parameters of methods are different in number, sequence and data types of
parameters. We can’t achieve method overloading by
changing just the return type, it will throw compilation error saying duplicate
method find in <class name>
Runtime/Dynamic polymorphism: (works along with inheritance)
It is also known as Dynamic Method Dispatch. Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime, that’s why it is called runtime polymorphism.
Example>>>> ABC parent class and XYZ child class
2. how do you run a test 10 times in testNG.
Ans: i) by using invocationCount parameter in @Test annotation as shown below…….
@Test(threadPoolSize = 3, invocationCount = 6, timeOut = 1000)
This configures the test method to be run in 3 different threads as defined in threadPoolSize. The other two attributes, invocationCount and timeOut, configures the test to be invoked 6 times and fail if the execution takes more time than 1000
ii) if you want to run the same test with different data you can do it by passing different sets of data through @DataProvider annotation (also called parameterization)
iii) or run the method inside @Test in a loop :D
3. when do we use @DataProvider over @Parameters in TestNG
Ans: In testNG xml <parameter name="browser" value="chrome"/>
<parameter name="browser" value="firefox"/>
You can’t run the test for both values (chrome,firefox) of same parameter(name) using @Parameters annotation.
@Test
@Parameters(browser) //takes only “chrome”
Public Void testMethod(String browser ){something;}
This can be achieved by @DataProvider or calling the same test twice in testNG xml with one parameter at a time………..
Without using @DataProvider>>>>>>>>>>>
(<parameter name="browser" value="chrome"/> <test>test1</test>, <parameter name="browser" value="firefox"/>
<test>test1</test>,)
Using @DataProvider>>>>>>>>>>>>>>>>>
@Test(dataProvider=”browser”)
@DataProvider(name=”browser”)
Public Object[][] getData(){
return new Object[][]{“chrome”,”firefox”,”ie”};
Public Void testMethod(String browser ){something;}
4. exception handling in java.
Ans: try catch block, throws.
5. Have you used collections in your framework?
Ans: yes, sets,queue,lists
6. difference between hashmap and hashtable?
Ans:
1.
HashMap is non synchronized. It is not-thread safe and can’t be shared between
many threads without proper synchronization code whereas Hashtable
is synchronized. It is thread-safe and can be shared with many threads.
2. HashMap allows one null key and multiple null values whereas Hashtable
doesn’t allow any null key or value.
3. HashMap is generally preferred over HashTable
if thread synchronization is not needed
Why
HashTable
doesn’t allow null and HashMap does?
To successfully store and retrieve objects from a HashTable,
the objects used as keys must implement the hashCode
method and the equals method. Since null is not an object, it can’t implement
these methods. HashMap is an advanced version and improvement on the Hashtable.
HashMap was created later.
7. Difference between abstract class and interface
Ans:
8. what is data encapsulation….(unlike abstract,interfaces… encapsulation and polymorphism are ideas/concepts in java that can be implemented where/how you want to)
9. can we create an object for abstract class?
Ans: we can’t create object for an abstract class. That means no one can see/access directly what is inside an abstract class and can access it’s methods only during implementation in the child classes.
10. difference between soap and rest services..
11. Architecture of selenium?
Ans: refer below.
12. Do you know readyAPI framework?
Ans: No
13. what is wsdl file
Ans: WSDL, or Web Service Description Language, is an XML based definition language. It's used for describing the functionality of a SOAP based web service. WSDL files are central to testing SOAP-based services. SoapUI uses WSDL files to generate test requests, assertions and mock services.
14.How does selenium interacts with web browser.
Ans:
There are four components of Selenium Architecture:
1. Selenium Client Library
2. JSON Wire Protocol over HTTP
3. Browser Drivers
4. Browsers
Selenium Client Libraries/Language Bindings:
Selenium supports multiple libraries such as Java, Ruby, Python, etc., Selenium Developers have developed language bindings to allow Selenium to support multiple languages. Check out Selenium Libraries in the official site.
JSON WIRE PROTOCOL Over HTTP Client:
JSON stands for JavaScript Object Notation. It is used to transfer data between a server and a client on the web. JSON Wire Protocol is a REST API that transfers the information between HTTP server. Each BrowserDriver (such as FirefoxDriver, ChromeDriver etc.,) has its own HTTP server.
Browser Drivers:
Each browser contains separate browser driver. Browser drivers communicate with respective browser without revealing the internal logic of browser’s functionality. When a browser driver is received any command then that command will be executed on the respective browser and the response will go back in the form of HTTP response..
Browsers:
Selenium supports multiple browsers such as Firefox, Chrome, IE, Safari etc.,
Let’s see how Selenium WebDriver works internally.
In real time, you write a code in your UI (say Eclipse IDE) using any one of the supported Selenium client libraries (say Java).
Example:
Once you are ready with your script, you will click on Run to execute the program. Based on the above statements, chrome browser will be launched and it will navigates to “https://4versatiles.blogspot.com” website.
Here we see what will happen internally after you click on Run till the launch of Firefox browser.
Once you click on Run, every statement in your script will be converted as a URL with the help of JSON Wire Protocol over HTTP. The URL’s will be passed to the Browser Drivers.
In
the above code, we took ChromeDriver). Here in our case the client
library (java) will convert the statements of the script to JSON format and
communicates with the ChromeDriver. URL looks as shown below.
Every Browser Driver uses a HTTP server to receive HTTP requests. Once the URL reaches the Browser Driver, then the Browser Driver will pass that request to the real browser over HTTP. Then the commands in your selenium script will be executed on the browser.
If the request is POST request then there will be an action on browser
If the request is a GET request then the corresponding response will be generated at the browser end and it will be sent over HTTP to the browser driver and the Browser Driver over JSON Wire Protocol and sends it to the UI (Eclipse IDE).
15. how do you do parallel testing
Ans: 1.through testng xml by defining thread-count="3" parameter, This will invoke 3 java threads at a time and the tests are distributed across threads and thus execution time reduces significantly.. ……….. Can run parallel=tests/methods/classes parallelly
2. using selenium grid concept.
3. Using Dataprovider annotation like below
@DataProvider(name = "dp1",parallel=true, threadPoolSize=10) [From comments below]4. Please mention it in comments if any other ways.
16.without using sendkeys how do you type text....
Ans: 1.javascript……… (JavascriptExecutor js = (JavascriptExecutor) driver;
//Typing in a Text Box
js.executeScript("document.getElementById('txtUsername').value='Admin';");)
//Getting Element Attributes
String className = js.executeScript("return document.getElementById('btnLogin').getAttribute('class');").toString();
2.using Robot class……… (Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_A);)
3. Please mention it in comments if any other ways.
17.what class/library files are used for xlsx sheets and xls sheets.
Ans: Apache POI library.
To read XLS files, an HSSF implementation is provided by POI library.
To read XLSX, XSSF implementation of POI library will be the choice
Refer to relevant videos for DEMO on this channel.
*****************************************************
*****************************************************
Hi Nice to see this post. For question 15, we can add one more method that using Dataprovider annotation like below
ReplyDelete@DataProvider(name = "dp1",parallel=true, threadPoolSize=10)
Thanks for your feedback. I have added your comment under question-15 answers
ReplyDelete