Selenium Code

Q.No1 How to Run Tests in Google Chrome 

First Create a Project in eclipse
2nd create a package
3rd create a class
then past below code


package Automation;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class launchchrome {
 
 
 public static void main(String[] arg)
 {
  
  System.setProperty("webdriver.chrome.driver", "E:\\study\\selenium\\chromedriver_win32\\chromedriver.exe");
  WebDriver driver=new ChromeDriver();
  driver.get("http://google.com");
 }

}

Q.No.2 How  to Run tests in Firefox Browser

First Create a Project in eclipse
2nd create a package
3rd create a class
then past below code

then past below code

package Automation;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class launchfirefox {


public static void main(String[] arg)
{
System.setProperty("webdriver.gecko.driver","E:\\study\\selenium\\geckodriver-v0.25.0-win32\\geckodriver.exe");
// download gecko driver, gecko driver is use for firefox broswer 
WebDriver driver=new FirefoxDriver();
driver.get("http://google.com");
}


}


What is TestNG ?

TestNg is a testing framework for java programming language created by cedric beust and inspired by Junit and Nunit.

Make test creation,execution and reporting efficient.

TestNg use annotation like
@BeforeTest                    @AfterTest
@BeforeClass                  @AfterClass
@BeforeSuit                    @AfterSuit
@BeforeMethod              @AfterMetthod

How to install TestNG for Selenium ?

Open eclipse go help menu and click Install new Software option.


Click on add button option
Put TestNG on name Text  box
And copy that url  https://dl.bintray.com/testng-team/testng-eclipse-release and past in loaction option.


Click on Add button then It will search and show here.


click on checkbox which is show on. and click Next 



After Next accept the agreement 

Wait for the installation to complete. 
 
You have installed TestNG successfully.

Why we use wait in selenium
the elements load time on a web page can vary, not all element are loaded at the same time. most of application are developed using JavaScript and ajax etc,object on web page may load at different time.

Implicit wait:- implicit wait in selenium is used to tell the web drive to wit a certain amount of time before it throw not such element exception. if once we set of time the web driver will wait for that time before throwing a exception 

Explicit wait:- explicit wait in selenium is used to tell the web driver to wait a certain condition or maximum time to exceeded before throwing "elementnotfoundexception" exception.


8 comments:

  1. High Technologies Solutions offers selenium training with choice of multiple training locations across Delhi. Further More Details Here-+91-9311002620 Or Visit Website- https://www.htsindia.com/Courses/Software-Testing/selenium-training-course-institute

    ReplyDelete
  2. Thanks for sharing this kind of content in your blog its very helpful for me and you put very knowledgeable content if anyone search for best institute for selenium course check this out Contact Here-+91-9311002620 Or VisitWebsite-https://www.htsindia.com/Courses/Software-Testing/selenium-training-course-institute

    ReplyDelete