After finished your recording save the test case as JUnit4 and give the file name as .java for an example i saved this file as search.java
File should be shown as below
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
public class search extends SeleneseTestCase {
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.lk/");
selenium.start();
}
@Test
public void testSearch() throws Exception {
selenium.open("/");
selenium.type("id=gbqfq", "blog");
selenium.click("id=gbqfb");
selenium.open("/");
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
How to use the eclipse for run the selenium script as a junit test
2.Create the java project
3.Name the project
4.Create the new folder
5.Name the folder as lib
6.Right click the lib folder and go to Build Path>Configure Path
7.Add the external selenium RC server and selenium client driver(Java) jar file .You can download this jar files from this link .
8.If you add the external files you can show under your project as shown below image . Add the external jar files then program can import the needs packages.
9. Right click your src folder under your project and create the package .
10.Right click your package what you create and create the file and name as what name should be given for your script then it should be easy.
11.Now you can open your file and copy and paste the scripts (above script) and make sure your package name and class name.Code shown below
package search.test;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings("deprecation")
public class search extends SeleneseTestCase {
DefaultSelenium selenium ;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.lk/");
selenium.start();
}
@Test
public void testSearch() throws Exception {
selenium.open("/");
selenium.type("id=gbqfq", "blog");
selenium.click("id=gbqfb");
selenium.open("/");
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
11.If you want to enhance the test case use the assert commands and verify your test case . For an example
assertEquals("Tittle of Page", selenium.getTitle());
Can use this kind of assert command and check . Finish your enhancement you want to start the server.
Open the command prompt and go to selenium-server-standalone-2.23.0.jar and run the server use this command :
java -jar selenium-server-standalone-2.23.0.jar
The architecture of selenium RC
12. Now you can run your test case in eclipse you can get a result with duration so it can be used as performance testing.
Reference :
Next blog i will continue how to create the test suites and how to get the test result use ant...
"I am enough of an artist to draw freely upon my imagination. Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."-Albert Einstein
0 comments:
Post a Comment