Active QA job

An Introduction to JUnit

Instead of jumping into selenium with java directly, lets make our-self familiar with some basic about JUnit and Eclipse.
JUnit is basically the standard unit testing library for java language. It is a unit testing framework, mostly used by  developers for the unit testing. It's latest version  4 introduces the new API with JAVA 5.0 annotations. So annotations can be used with simple user created class instead of extending or using inheritance. JUnit 4  comes inbuilt with eclipse. You have to add JUnit library in your project.
Some important annotations for selenium users:
@Test
@Before
@After
@Ignore
@BeforeClass
@AfterClass
@Parameters
@RunWith
@Suite
......
Some knowledge about these annotations is helpful to start selenium testing with Eclipse/JUnit.  javadoc of JUnit API  is also very helpful to learn in detail.

Brief Introduction to selenium Scripting(Simple)

If you don't have selenium IDE, Go here.
Two major features of Selenium IDE is record and play. Selenium starts recording  if the red button on the right hand corner is on. Script is divided into three different parts: Command, Target and Value. Selenium has three types of commands; Actions, Accessors and Assertions
Common Selenium  commands recorded by IDE are: open, type, click, click.., select, ...AndWait suffix eg clickAndWait, addSelection and etc.
Assertions are used to compare the actual result with the expected result. They have 'verify' 'assert' and 'waitFor' prefix. During recording user can simply right click and add these assertion for verification purpose or can be added later on.
'waitFor' command waits until some condition is true. They do not wait if targeted condition is met but wait for some time if something is in progress. It is very useful to verify Ajax.
Verify Vs Assert:
What is t he difference between verify and assert? when to use what?
When assert fails, current test script stops running and test in progress jumps to another test script. When verify fails, it logs the error but same script keeps running.  So when to use what is your choice. But you can always borrow some idea from best practice.
If you are verifying many elements is present in a  page, you can 'assert' the title of the page to make sure you are in the right page. If you are in the wrong page, its OK even script stops running right?
Assert is best used for critical part of the application, such as log-in verification. Once you are  logged in with an username you can assert that particular used name is there.

Java

Some Rules in Java:

  • A source code file can have only one public class and may have multiple non-public class
  • A public class  file name must match the public class name.
  • A file can have only one package statement and it must be the first line in the source code.
  • A file can have multiple imports.
  • Import statement is applicable to all classes in the source code file
  • If a class cannot be accessed, its members (methods and instance variables) cannot be accessed either.
  • A subclass can inherit a member of its super-class.A subclass can only extend one parent.
  • A class access determines its members' access. If a  class cannot be access, its member's cannot be accessed either.
  • 'this.' means currently executing object.
  • Private members cannot be inherited.

Package in Java

What is a package?
A package is a directory that contains related groups of classes and interfaces. Packages hides its class and interfaces in a separate directory.
A package is a kind of directory that contains a group of related classes and interfaces. Java has many such packages it its library. If you want to use a classes, you  have to import it into your program. If you want to use a method, then you have to import the corresponding class or interface.
A group of package is called library. Any class and interface inside a package is reusable.
When a package is imported, its sub packages are not automatically imported into a program. A separate import statement should be written to for every package or sub package

Java library
      |
Packages
      |
Classless and interfaces
      |
methods

There are two different types of pacakges
1. build-in
2. User defined 
Build -in Packages
Build -in packages are already available in Java. these pacakes provide all necessary classes, interfaces and methods to perform tasks. Some important packages are:
java.lang:   This package has primary classes and interfaces for developing a basic Java program.
java.util: It has many useful collections. Date, time operations, victors... 
java.awt:awt stands for Abstract Window Toolkit.Tis pacakge is useful for develiping GUI-color, paintings, images etc.It consists one important sub-package java.awt.event . It provides actions like select radio button, menu.
javax.swing: Helpful for GUI. It is an extended package of java,awt(package developed from another package by adding new features). 'x' represents it as an extended package.
java.net: Useful for authentication for network, creating sockets, to establish communication between client-server.
java.applet: Related to Java applets.
java.text: It contains two important classes. 'DateFormat' is to format date and time. 'Numberformat' is to format numeric values.
java.sql: Helps to connects to the database like oracle, retrieve and use data in Java program.

User-Defined Package: 
Package created by user. User defined package can be used exactly same way as the build-in package. 
The keyword to create a package is package.