Showing posts with label Java and manual with Ans. Show all posts
Showing posts with label Java and manual with Ans. Show all posts

Saturday, May 24, 2014

Advanced level FAQ on Selenium-WebDriver, Java and manual with Ans

Ques1- How the TestNG class's execution happen ?

Ans- as soon as we trigger the xml, it will search for TestNG annotations and it will start executing accordingly. For ex- suppose in the module, these annotation have been used- @BeforeClass, @BeforeMethod, @Test, @AfterClass, @AfterMethod
then the order of execution-
@BC → @BM → @T → @AM → @BM → @T → @AM → @AC.


Ques2- Which type of test cases u select to automate and why ?

Ans- a) High Risk - Business Critical test cases
b) Test cases that are executed repeatedly
c) Test Cases that are very tedious or difficult to perform manually
d) Test Cases which are time consuming
Because to do these test cases manually its very difficult, time consuming and repeating job.

Ques3- How do you handle https website in selenium ?

Ans- By changing the setting of FirefoxProfile.
public class HTTPSSecuredConnection {
public static void main(String[] args){
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(false);
WebDriver driver = new FirefoxDriver(profile);
driver.get("https://184.106.253.74");
}
}

Ques4- What is regular expression ?

Ans- a sequence of symbols and characters expressing a string or pattern to be searched for within a longer piece of text.

Ques5- What is the difference b/w Keys.RETURN and Keys.ENTER ?
Ans- Keys.RETURN → it is used to press Enter key.
Keys.ENTER → is used to press Tab key.

Ques6- When to use WebDriverBackedSelenium ?

Ans- WebDriverBackedSelenium is a kind of class name where we can create an object for it as below: Selenium wbdriver= new WebDriverBackedSelenium(WebDriver objectName, "URL path of website").
The main use of this is when we want to write code using both WebDriver and selenium RC , we must use above created object to use selenium commands.

Ques7- What is the package name which is to be imported while working with WebDriver?

Ans- org.openqa.selenium

Ques8- How to check if an element is visible on the web page ?

Ans- using isDisplayed() method. Return type of this method is boolean. So if this method returns true then element is visible else if returns false then element is not visible.

Ques9- How to check if a button is enabled on the page ?

Ans- Using isEnabled() method. Return type of this method is boolean. So if this method returns true then element is visible else if returns false then element is not visible.

Ques10- How to insert a comment in selenium IDE ?

Ans- Open the test case and select the row before which you want to insert the comment then → go to edit → insert new comment → it will insert the comment line before the selected line, comment text write in the command line.

Ques11- How do you read the text from the hidden elements ?

Ans- First move the cursor over the element where element is hidden to make the element visible then use the getText() method.

Ques12- What is the use of apache poi ?

Ans- It is used to read and write the data from excel files or say to handle excel files data.

Ques13- How to check whether a text is underlined or not ?

Ans- Use webElement.getCssValue(“text-decoration”), if this return underline then that element is underlined else not.

Ques14- How to press Shift+Tab ?

Ans- Use chord() method to pass the combinations of keys.
String keys = Keys.chord(Keys.SHIFT,Keys.TAB)
webelement.sendKeys(keys); or act.sendKeys(keys);

Ques15- How to enter : (colon) using web driver ?

Ans- String keys = Keys.chrod(Keys.SHIFT,Keys.SEMICOLON);
webelement.sendKeys(keys);

Ques16- Which type of test cases should convert in Automation test cases ?

Ans- a) Regression test cases or repeating test cases
b) High Risk - Business Critical test cases
c) Test cases that are executed repeatedly
d) Test Cases that are very tedious or difficult to perform manually
e) Test Cases which are time consuming

The following category of test cases are not suitable for automation:
a) Test Cases that are newly designed and not executed manually atleast once.
b) Test Cases for which the requirements are changing frequently.
c) Test cases which are executed on ad-hoc basis.

Ques17- Why are you using hybrid framework ?

Ans- Tell the advantages- code re-usability, Fastest and less costly way to develop the automation scripts due to higher code re-usability, Utilizing a modular design, and using files or records to both input and verify data, reduces redundancy and duplication of effort in creating automated test scripts.

Ques18- What is your responsibilities in your framework ?

Ans- working end to end → designing, implementation and execution.
  • Developing methods for repeating steps.
  • Writing scripts, executing test cases and debugging.
  • Prepare automation scripts in Selenium WebDriver.
  • Regression Testing, support and reviewing Test scripts.
  • Data driving Test script.
  • Defect reporting, Executing Framework and Analyzing Result.

Ques19- Why framework is needed and what are the uses ?

Ans - Framework is a set of guidelines like coding standards, test-data handling , object repository treatment etc.. which when followed during automation scripting produce beneficial outcomes like increase code re-usage, higher portability, reduced script maintenance cost etc. Mind you these are just guidelines and not rules; they are not mandatory and you can still script without following the guidelines. But you will miss out on the advantages of having a Framework. So its always best practice to have good framework.

Ques20- What are the challenges you faced in selenium and how do you overcome ?

Ans- Make sure you have solutions for all the challenges which you are going to tell. Better tell these 1st six chanllenges.
1. Handling popups
2. Switching between windows
3. Working with frames.
4. Field validation
5. How to identify dynamic objects.
6. Xpath and CSS locators for identifying elements.

Advance level -
• Dealing with pop-up windows
Testing dynamic text or content
How to go about testing Flash
Capturing screen shots, either to file or in some form of report
Iteration of the test case, running it repeatedly with some minor change
Data Driven Testing, using suites of pre-cooked data or generating it on the fly
Generating useful test status reports
Setting up Remote Control
Setting up Grid

Ques21- What is reflection API, with example ?

Ans- Reflection is the process of examining or modifying the runtime behaviour of a class at runtime.
The java.lang.Class class provides many methods that can be used to get metadata, examine and change the runtime behaviour of a class.
Where is it used?
The Reflection API is mainly used in:
IDE (Integreted Development Environment) e.g. Eclipse, MyEclipse, NetBeans etc.
Debugger
Test Tools etc.

Ques22- Stress vs load testing vs performance testing. Can we use selenium for the performance testing ?

Ans- Stress testing - testing by applying the load more than expecting.
Load Testing- testing with the expected numbers of users
Performance- testing by applying the load and then check the time how much its taking to complete the test case.
Yes we can do performance testing using selenium. You can say using invocationCount and threadPoolSize, performance testing can be done.

Ques23- Give an example for abstraction (write a program).

Ans- interface QSG{
void startEngine():
}
class Benz implements QSG{
public void startEngine(){
System.out.println(“Start benz car.”);
}
public static void main(String[] args){
Benz car = new Benz();
car.startEngine();
}
}

Ques24- How to identify dynamic objects ?

Ans – By using xpath().

Ques25- xpath and CSS locators for identifying elements.

Ans- xpath() and cssSelector() both are the static method of By class which is used to find the WebElement in a webpage.

Ques26- How will you handle drop down list ?

Ans- If dropdown list has been developed using select tag then we can use the Select class methods (selectByValue(), selectByIndex(), selectByVisibleText()) or else we can use the Actions class by moving cursor over dropdown menu and then select the element which you want to select by clicking on that.

Ques27- How will you handle download popup ?

Ans- To handle download pop ups, we need to set the preference of the browser. Create an object of the FirefoxProfile and use setPreference() method then open the firefox browser like this – WebDriver driver = new FirefoxDriver(profile).

Ques28- What are the different browsers you have used ?

Ans- Firefox, IE, Chrome. Mainly firefox is used.

Ques29- What are the settings to be done in case of IE, chrome and Firefox browsers before opening them ?

Ans- a) For firefox no setting is required.
b) For IE need to set the property of the System class-
syntax- System.setProperty(“webdriver.ie.driver”,”path of the ie exe driver file”);
c) For chrome, need to set the property of the System class-
syntax- System.setProperty(“webdriver.chrome.driver”,”path of the chrome exe driver file”);

Ques30- What is the difference between overloading and overriding ?

Ans- Overloading- developing the methods with different arg type.
Overriding- developing the methods with same signature but having different method body. Its possible in non-static methods only.

Ques31- How do you use selenium ide ?

Ans- very rarely it is used. Initially we used this. Its an Addons on Firefox browser. 1st we need to launch the Selenium IDE. Go to tools and there you will find this. As soon as we launch this , it will open in record mode. Then open the browser manually and open your application and start doing the testing. After completion of test case go to Selenium IDE and click on File and save as test case and give the test case name. Now whenever you want to run that again go to file and browse it and run. This tool is like play back recording tool.

Ques32- What are the test cases for date picker ?

Ans- click on the date field calendar should be shown, present date should be selected, after selecting the desired date calendar should be disappear, date format should be present beside the label of date, date format should be accepted by the field as expected, characters/special characters fields should not be accepted.

Ques33- Write Query to select top two employee salaries from Employee table.

Ans- Select salary from Employee
order by Salary desc fetch first 2 rows only;

Ques34- If assertion fails how do you handle that ?

 Ans- will use try catch block to handle the exception.

Ques35- Difference between abstract class and interface.

Ans- abstract class- if class having even a single method as incomplete then that class will become abstract class but this can have complete as well as static method both. We can't create instance of abstract class. But using abstact class we can't achieve 100% abstraction. It can not be final class.
Interface- it can have only incomplete methods. All the methods are public and non-static. Any variable dec inside this is always final and static. 100% abstraction is achievable. Supports multiple inheritance.

Ques36- How to find broken links on a web page using selenium WebDriver ?

 
Ans- List<WebElement> links = driver.findElements(By.tagName(“a”));
String linkUrl = null;
for(WebElement link: links){
linkUrl = link.getAttribute(“href”);
URL url = new URL(linkUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setConnectTimeout(3000);
httpURLConnection.connect();
if(httpURLConnection.getResponceCode==HttpURLConnection.HTTP_NOT_FOOUND){
System.out.println(link);
}
}

Ques37- Reverse a given statement

Input: “This is a book”

Output: “book a is This”

Ans- class Reverse{
public static void main(String args[]) {
String input = "This is a book";
String output = "";
int l=input.length();
int j =0;
for(int i=l-1; i>=0; i--){
j++;
if(input.charAt(i)==' '){
output = output+input.substring(i+1, l)+" ";
l = l-j;
j=0;
}
if(i==0 && input.charAt(i)!=0){
output = output+input.substring(i, l);
}
}
System.out.println(output);
}
}

Ques38- Test coffee winding machine.

Ans- While running the machine it should not throw any current, tank where water and milk have been filled should not leakage, speed of running the motor should be controlable by the regulator, when power button switch on machine should be started, when power button is off, machine should stop in given time range., while running the machine should not move here and there etc.

Ques39- Test cases to test a Pen.

Ans- 1st will go thru the requirement then only we start writing test cases. So here I am considering pen which is having refill normally used by people.
color of words written in the paper should be same as link filled in refill, while writing on the paper , refill should not come outside the pen, grip of pen should be good , it should not slip from hand while writing, logo of brand should be visible and should be in correct place, in normal temperature pen ink should not be freeze or come out of the refill, while having the pen in pocket ink should not come out, cap of should be fit, check how it works on rough paper, check if it writes on hand or not because sometime people write on hand, check the length of the written words is as per expectation means life of refill etc.

Ques40- How do you test the particular website like pizza ?

Ans- Using Selenium WebDriver, TestNG tool. Tell some test cases like- by entering the url of the website, it should open the website and be accessible by everyone., all the links in site should work, by clicking on offers or menu it should throw on the correct page, all the dropdown should be visible after moving the cursor over those elements, while ordering the pizza, it should ask for the confirmation etc.

Ques41- Using selenium can we test the machines ?

Ans- using selenium , we can test only web applications. Machines we can't test using selenium.

Ques42- Top 5 most critical conditions to test the travel website.

Ans-1) if one way trip has selected and searching for the available options, it should not ask for the return date and should show only those options which are available on the date given by user and should show only those trains/flights which are passing from the source and destination, 2) the options which are available all should be selectable and open for the booking. 3) if round trip selected then it should ask for return date and should show both the trains/flight, 4) while making the payment, it should show the correct fare with all calculation and it should route to correct bank website for payments 5) after making the payment , ticket should be generated with the unique PNR number and success msg should be shown to customer.

*Ques43- A pond contains some flowers at the first day, next day flowers in the pond gets double. If the pond gets full at 20th day then which was the day pond was half ?

Ans- Think yourself. (ans is given at the end of the post).

Ques44- Which oops concept are you using in Data driven framework ?

Ans- Polymorphism.

Ques45- How to select last value from the dropdown without using getOption() ?


Ans- public
class SelectLastOption {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver()driver.get("file:///C:/selenium/sank_java/selenium/WebDriver/Selenium_web.html");
driver.findElement(By.xpath("//select[@id='sdd']")).click();
List<WebElement> list = driver.findElements(By.xpath("//select[@id='sdd']//option"));
list.get(list.size()-1).click();
}
}

Ques46- Difference between Hashtable and HashMap.

Ans- Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.
Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.

Ques47- Difference between Array and ArrayList.

Ans- a) Array is a fixed length data structure while ArrayList is a variable length Collection class.,
b) can not use Generics along with Array, as Array instance knows about what kind of type it can hold and throws ArrayStoreException, if you try to store type which is not convertible into type of Array. ArrayList allows you to use Generics to ensure type-safety.
c) Array provides length variable which denotes length of Array while ArrayList provides size() method to calculate size of ArrayList in Java.
d) can not store primitives in ArrayList, it can only contain Objects. While Array can contain both primitives and Objects in Java. Though Autoboxing of Java 5 may give you an impression of storing primitives in ArrayList, it actually automatically converts primitives to Object.

Ques48- Automation test life cycle (ATLC).

Ans- Automation test life cycle-→ Test Tool Selection
→ Define scope of automation
→ Planning, Design and development
→ Test Execution
→ Maintenance.

Ques49- Why css selector is faster than xpath ?

Ans- CSS selectors are also a bit easier to use and more stable since it uses more class and ID attributes which are more stable than node hierarchy. Of course there are also bad ways to write css that makes it brittle.
There is also a performance advantage. Browsers already have built in native functions that run much faster for selecting css since it's an HTML standard. While xpath on the other hand is an XML standard and isn't as optimized on the browser end.

Ques50- What is nullpointer exception ?

Ans- A null pointer exception is caused when you de-reference a variable that is pointing to null.

*Ans43- on 19th day.