There are essentially two tasks:
For Java, we need to use either JUnit or TestNG as the test engine. Some development environments like Eclipse have direct support for these via plug-ins. This makes it even easier. You will probably want to rename the test class from “NewTest” to something of your own choosing.
Also, you will need to change the browser-open parameters in the statement
selenium = new DefaultSelenium(“localhost”, 4444, “*iehta”, “https://www.google.com/”);
The Selenium-IDE generated code will look like this. This example has comments added manually for additional clarity.
package com.example.tests;
// We specify the package of our tests
import com.thoughtworks.selenium.*;
// This is the driver’s import. You’ll use this for instantiating a
// browser and making it do what you need.
import java.util.regex.Pattern;
// Selenium-IDE add the Pattern module because it’s sometimes used for
// regex validations. You can remove the module if it’s not used in your
// script.
public class NewTest extends SeleneseTestCase {
// We create our Selenium test case
public void setUp() throws Exception {
setUp( “https://www.google.com/” , “*firefox” );
// We instantiate and start the browser
}
public void testNew() throws Exception {
selenium.open( “/” );
selenium.type( “q” , “selenium rc” );
selenium.click( “btnG” );
selenium.waitForPageToLoad( “30000” );
assertTrue(selenium.isTextPresent( “Results * for selenium rc” ));
// These are the real test steps
}
}
Checkout Selenium Interview Questions
The parameters required when creating the browser instance are:
host Specifies the IP address of the computer where the server is located. Usually, this is the same machine as where the client is running, so in this case localhost is passed.
port Specifies the TCP/IP socket where the server is listening waiting for the client to establish a connection.
browser The browser in which you want to run the tests. This is a required parameter.
url The base url of the application under test. This is required by all the client libs and is integral information for starting up the browser-proxy-AUT communication.
This section will explain how to set up selenium in Eclipse.
Achala Solutions will deliver the work in four phases as listed below. Each of the phases and activities are described in the following picture
https://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.5.2-201002111343/eclipse-SDK-3.5.2-win32.zip
https://java.sun.com/javase/downloads/index_jdk5.jsp
Related Page: How To Create Test Suites In Selenium
1. Create an empty folder (Selenium_Scripts1) in F drive-no need to create in F drive you can create folder in any folder.
2. Create an empty folder lib in Selenium_Scripts1 folder.
3. Install jdk1.5.0_11, copy the jdk1.5.0_11 folder which is in c folder
(Generally it will be installed in “C” Drive– C:Program FilesJava) and paste it in Selenium_Scripts1 folder.
4. Paste the 4 Jar files (junit-4.5, jxl, selenium-java-client-driver, and seleniumserver) in lib folder.
5. Open eclipse (F: eclipseeslipse.exe)
You will get the below window, select the path (F: Selenium_Scripts1) which you created a folder earlier in F drive.
After clicking OK, you will get below screen select “work bench”.
You will get the below screen—eclipse environment.
1. File—New—Java Project
2. Give Project name (Selenium_scripts)
3. Click Configure JREs in that screen. You will get a new window.
4. Click Add—Standard VM????next.
JRE Home—we need to specify path.
Click directory—browse the path where you created the folder
(F:Selenium_scripts1jdk1.5.0_11jre)
All jar files will be added.. click Finish and click OK
Click finish on the open window (New Java Project window)
You can see the new project Selenium_scripts in eclipse window.
New Java Project with all jar files.
Now Right click on JRE System Library[Java SE-1.6]
Select Build Path- configure Build Path.
A new window will be opened. Select Libraries tab and click Add External Jars Button.
Select path F:demolib and select all 4 Jar files click OK.
You can see all Jar files under Libraries Tab.
Click Ok.
You can see the Referenced Libraries…
Everything is done.
Go to RUN External Tools External tools configuration…
There click Program—u will get new configuration window.
Give name selenium server (any name you can give).
Location —click on Browse file systems. F:Selenium_Scripts1jdk1.5.0_11binjava.exe
Working Directory— Browse file system — F: Selenium_Scripts1lib.
Arguments – -jar selenium-server.jar
Click Apply and Run….
Related Page: Automation Selenium RC Using TestNG - Selenium
Now, you can write your scripts and Enjoy Selenium Automation….
File – New –class
Give Name First and click the check box public static void main (String [] args) click Finish.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Selenium Training | Nov 19 to Dec 04 | View Details |
Selenium Training | Nov 23 to Dec 08 | View Details |
Selenium Training | Nov 26 to Dec 11 | View Details |
Selenium Training | Nov 30 to Dec 15 | View Details |
Madhuri is a Senior Content Creator at MindMajix. She has written about a range of different topics on various technologies, which include, Splunk, Tensorflow, Selenium, and CEH. She spends most of her time researching on technology, and startups. Connect with her via LinkedIn and Twitter .