Selenium Question 6

Q1. What is the use of property file?

It is similar to object repository. For reading the value from properties file we create a object with class properties.
Properties prop = new properties();
Prop here help to get the contents from a properties file.
FileInputStream IP = new FileInputStream(“Property file path”)
It will write the value in property file.
It helps to create loosely coupled frame work.

Q2. What is the use of system.getproperty(user.dir)?

It give us the current path of directory we are working on

Q3. What is POI API?

It is used to read excel files in java
We do this by right click on project and go to project properties, go to java build path, click on libraries tab.
Click on add external jar buttons and select the POI API Jar files.

Q4. While running a selenium we what to know what actually have happened if some thing pass or fail?

So we need to generate the logs, add a jar file name log4J.
This jar contain lot of packages and classes, we are concern about
It contains the information about the log file we have to create, just specify the path.
To use this file under a class:- Create a object of the class present in log4js
Logger Application_LOGS = logger.getlogger(“devpinologger”)
This will write the logs.

Q5. What is role of Junit

Ex we have 4 selenium script , we have excel file, generate logs and generate logs.
So we need a centralized controller so we use Junit or Test Ng.
 For junt frame work.
 Create a new project -> go to properties -> library and select Junit or add from library.
Junit comes with eclipses.
 Now cerate a new class and do not create any main function (as there is no main function in Junit there are annotations. Junit annotations are known as @Test and import junit files.
 @test it’s a predefined class in Junit.
 Add some functions
 We have Junit window which show have reports.
Write test word in front of every function, other wise Junit will not work fine
 @before this function is call before calling any @test functions.
 @before this function is call after calling any @test functions.
 @beforeclass :- this will be the first function which will be called.
 @ Afterclass :- this will be the last function which will be called.
 @beforeclass, @ Afterclass functions should be static.
 @Ignore on the top of any function, that function will not be called.
 Assume.assumeTrue(False); will halt the execution of a test.
How to parameterize using Junit.
1. Write @RunWith (Paramatrized.class) on top of class you want to parametrize. 
2. Declare some global variable, which will act as input doe any variable. 
3. Build a constructor of the class so class can be initialized. 
4. Add a annotation @parameters
Q6. Error Collector In Junit. 

It’s a in build class in Junit, help to report errors in Junit. Assertion are used in it :- it see is any condition true or not.Eg assert.assertequal(“Hellow”,”Hellow”)
Draw back if assertion fail the code after assert will not be executed, code execution fail., we can handle with try catch block
Assert.asserttrue (“error message”, 3>1)
Condition is false then only error message will be printed.
For reporting any error we create a object of class errorcollector and put @rule on it
Public ErrorCollector = errcol = new errocollector()
Now on the catch block write
Catch (Throwable t)
Now In junit error will be reported.

Q7. Batch running in selenium using Junit framework.

We user runners in junit , class is known as runner class
Create a class
Over it write
Q8. Clicking on a button?

Webelement username_button = Driver.findelement (By.Xpath(Button Xpath));

Q9. If we have multiple fields do we have to write every time Driver.findelement.By.Xpath ?

We can do
driver.findelement(By.Xpath(“field Xpath”).sendkey(“xxx”).
driver.findelement(By.Xpath(“button Xpath”).click().

Q10. Clear function?

To clear any text box.

No comments:

Post a Comment