KEMBAR78
Selenium with java | PPTX
What is WebDriver?
• WebDriver is a web automation framework, allows you to
execute your tests against different browsers, not just
Firefox.
• It Supports almost all browser
• It uses programming languages:
• JAVA
• PHP
• Python
• PERL
• Many more..
Step 1 - Install Java on your computer (Latest JDK)
Go to http://ninite.com and choose the JDK.
Step 2 - Install Eclipse IDE
Go to https://ninite.com/
Step 3 - Download the Selenium Java Client Driver
http://docs.seleniumhq.org/download/
• Launch the "eclipse.exe" file inside the "eclipse" folder.
• When asked to select for a workspace, just accept the
default location.
• Create a new project through File > New > Java Project.
Name the project as "newproject".
• A new pop-up window will open enter details as follow
1. Project Name
2. Location to save project
3. Select an execution JRE
4. Select layout project option
5. Click on finish button
Configure Eclipse IDE with WebDriver
• In this step,
• Right-click on the newly created project and
• Select New > Package, and name that package as
"newpackage".
• A pop-up window will open to name the package,
Enter the name of the package
Click on finish button
• Create a new Java class under newpackage by right-clicking
on it and then selecting- New > Class, and then name it as
"MyClass". Your Eclipse IDE should look like the image
below.
Configure Eclipse IDE with WebDriver
• When you click on Class, a pop-up window will open, enter
details as
• Name of the class
• Click on Finish button
• Now selenium WebDriver's into Java Build Path
• In this step,
• Right-click on "newproject" and select Properties.
• On the Properties dialog, click on "Java Build Path".
• Click on the Libraries tab, and then
• Click on "Add External JARs.."
Configure Eclipse IDE with WebDriver
• package mypackage;
•
• import org.openqa.selenium.WebDriver;
• import org.openqa.selenium.firefox.FirefoxDriver;
•
• public class myclass {
•
• public static void main(String[] args) {
• // declaration and instantiation of objects/variables
• WebDriver driver = new FirefoxDriver();
• String baseUrl = "http://newtours.demoaut.com";
• String expectedTitle = "Welcome: Mercury Tours";
• String actualTitle = "";
•
• // launch Firefox and direct it to the Base URL
• driver.get(baseUrl)
First Webdriver code
• // get the actual value of the title
• actualTitle = driver.getTitle();
•
• /*
• * compare the actual title of the page witht the expected one and print
• * the result as "Passed" or "Failed"
• */
• if (actualTitle.contentEquals(expectedTitle)){
• System.out.println("Test Passed!");
• } else {
• System.out.println("Test Failed");
• }
•
• //close Firefox
• driver.close();
•
• // exit the program explicitly
• System.exit(0);
• }
•
• }
First Webriver code
• WebDriver provides these useful get commands:
• get()
• getTitle()
• getPageSource()
• getCurrentUrl()
• getText()
WebDriver get commands

Selenium with java

  • 2.
    What is WebDriver? •WebDriver is a web automation framework, allows you to execute your tests against different browsers, not just Firefox. • It Supports almost all browser • It uses programming languages: • JAVA • PHP • Python • PERL • Many more..
  • 3.
    Step 1 -Install Java on your computer (Latest JDK) Go to http://ninite.com and choose the JDK. Step 2 - Install Eclipse IDE Go to https://ninite.com/ Step 3 - Download the Selenium Java Client Driver http://docs.seleniumhq.org/download/
  • 4.
    • Launch the"eclipse.exe" file inside the "eclipse" folder. • When asked to select for a workspace, just accept the default location. • Create a new project through File > New > Java Project. Name the project as "newproject". • A new pop-up window will open enter details as follow 1. Project Name 2. Location to save project 3. Select an execution JRE 4. Select layout project option 5. Click on finish button Configure Eclipse IDE with WebDriver
  • 5.
    • In thisstep, • Right-click on the newly created project and • Select New > Package, and name that package as "newpackage". • A pop-up window will open to name the package, Enter the name of the package Click on finish button • Create a new Java class under newpackage by right-clicking on it and then selecting- New > Class, and then name it as "MyClass". Your Eclipse IDE should look like the image below. Configure Eclipse IDE with WebDriver
  • 6.
    • When youclick on Class, a pop-up window will open, enter details as • Name of the class • Click on Finish button • Now selenium WebDriver's into Java Build Path • In this step, • Right-click on "newproject" and select Properties. • On the Properties dialog, click on "Java Build Path". • Click on the Libraries tab, and then • Click on "Add External JARs.." Configure Eclipse IDE with WebDriver
  • 7.
    • package mypackage; • •import org.openqa.selenium.WebDriver; • import org.openqa.selenium.firefox.FirefoxDriver; • • public class myclass { • • public static void main(String[] args) { • // declaration and instantiation of objects/variables • WebDriver driver = new FirefoxDriver(); • String baseUrl = "http://newtours.demoaut.com"; • String expectedTitle = "Welcome: Mercury Tours"; • String actualTitle = ""; • • // launch Firefox and direct it to the Base URL • driver.get(baseUrl) First Webdriver code
  • 8.
    • // getthe actual value of the title • actualTitle = driver.getTitle(); • • /* • * compare the actual title of the page witht the expected one and print • * the result as "Passed" or "Failed" • */ • if (actualTitle.contentEquals(expectedTitle)){ • System.out.println("Test Passed!"); • } else { • System.out.println("Test Failed"); • } • • //close Firefox • driver.close(); • • // exit the program explicitly • System.exit(0); • } • • } First Webriver code
  • 9.
    • WebDriver providesthese useful get commands: • get() • getTitle() • getPageSource() • getCurrentUrl() • getText() WebDriver get commands