Search |
||
Selenium-ANT-TestNG (SAT) FrameworkPosted by aditya_dada on May 20, 2008 at 10:39 AM PDT
This framework is created using ANT, TestNG and Selenium. Pre-requisites:Basic knowledge of Selenium IDE, Selenium RC, TestNG and ANT. Setup:1. Install Selenium IDE on your Firefox browser. 2. Make sure you have ANT installed. 3. Grab the testws.zip file from here. Unzip it into a directory of your choice. About the sample The config directory contains testng.xml file, and is a place holder for configuration files. How To:Write a test case The basic structure that one has to follow to create a test case is: 1. Record a testcase using Selenium IDE (Firefox browser only), Export the test case into Java 2. Edit the test case – java file, and add TestNG annotations 3. Execute the test case using ANT 1. Record test using selenium IDE and export it into Java: 2. Add TestNG to your test case: @AfterSuite(alwaysRun = true) iii. Save the test file iv. Ensure that the test file you created is mentioned in the build.xml compile target. 3. Execute your test through ANT »
Related Topics >>
Testing Comments
Comments are listed in date ascending order (oldest first)
Submitted by saisaphire on Fri, 2008-07-11 04:39.
Hi, I have problem :
1. When i try to run selenium test and the host target is http://localhost:8080/, my browser (opera 9.5) hang, and do nothing after initial new window. Command on console to start selenium server: java -jar selenium-server.jar -multiwindow.
Everything is ok until process try to create new DefaultSelenium(......)
2. I try to change browser to Firefox 3, and everything is stop for a long time, when selenium try to prepare profile for firefox.
Thanks.
Regards,
Sai
Submitted by kk_sriram on Thu, 2008-05-22 23:57.
The blog was informative.Can you paste your build.xml used by ant script?
Can we start the selenium server through ant script itself?
Submitted by aditya_dada on Tue, 2008-05-27 15:00.
Yes, the selenium server can be started through ANT script. Here's the snippet that will start the server:
...
<target name="start-selenium-server">
< java jar="${ws.home}/lib/selenium-server.jar" fork="true"/>
</target>
...
The current issue is that the command will hang after it starts server. so you 'll have to do the rest of the steps in another window. or use 'start' command on windows to start selenium in the background. e.g.
<target name="start-selenium-server">
<exec executable="start" failonerror="false" dir="testws/lib">
<arg line="java -jar selenium-server.jar"/>
</exec>
</target>
Submitted by niju on Thu, 2008-09-25 04:58.
Hi i have tried to create a frame work following Aditya's steps.
e) On top of the test method:
@Test(groups = { "" })
e.g. @Test(groups = { "roller" })
My script is below and it gives error
compile:
[echo] making directory...
[mkdir] Created dir: C:\Framework\testws\build
[echo] classpath: C:\Framework\testws\lib\junit.jar:C:\Framework\testws\lib
\selenium-java-client-driver-tests.jar:C:\Framework\testws\lib\selenium-java-cli
ent-driver.jar:C:\Framework\testws\lib\selenium-server-0.9.1-20070223.200626-116
-standalone.jar:C:\Framework\testws\lib\selenium-server.jar:C:\Framework\testws\
lib\testng-5.5-jdk15.jar:C:\Framework\testws\lib\testng.jar
[echo] compiling...
[javac] Compiling 1 source file to C:\Framework\testws\build
[javac] C:\Framework\testws\test\UsersFilter.java:17: expected
[javac] usersPage();
[javac] ^
[javac] 1 error
BUILD FAILED
C:\Framework\testws\build.xml:68: Compile failed; see the compiler error output
for details.
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import junit.framework.*;
import java.util.*;
import java.lang.*;
@Test(groups = { "UserFilter" })
public class UsersFilter extends SeleneseTestCase {
public static Selenium browser;
public static void main(String args[]) {
browser = new DefaultSelenium("localhost", 4444, "*chrome",
"http://192.168.2.63/aveksa/main");
browser.start();
@Test(groups = { "UserFilter" })
usersPage();
}
public static void usersPage() {
//Logging in to the application
browser.open("http://192.168.2.63/aveksa/main");
browser.type("Name1", "AveksaAdmin");
browser.type("Pass1", "Aveksa123");
browser.click("//span[@id='login']/span");
System.out.println("Login successful");
browser.waitForPageToLoad("30000");
assertTrue(browser.isElementPresent("UsersTab"));
browser.click("UsersTab");
browser.waitForPageToLoad("30000");
System.out.println("Opened Users Tab");
//Checking the no. of records under Users tab
assertTrue(browser.isTextPresent("Rows 1 - 10 of 75"));
System.out.println("Rows 1 - 10 of 75 displayed");
assertTrue(browser.isElementPresent("//img[@title='Filter Data']"));
/*assertTrue(browser.isElementPresent("//img[@title='Table Columns']"));
browser.click("//img[@title='Table Columns']");
browser.waitForPopUp("ColumnsDialogData", "30000");
browser.selectWindow("name=DialogIframe");
assertTrue(browser.isElementPresent("//fieldset[@id='ColsFieldset']/div"));
browser.open("/aveksa/main?ReqType=Table&PageID=ColumnsDialogData&Action=Content&TableID=UsersSummaryTable");
browser.click("col_department");
browser.click("col_supervisorName");
browser.click("col_title");
browser.click("col_jobStatus");
browser.click("col_CUS_ATTR_USER_CAS_2");
browser.click("col_CUS_ATTR_USER_CAS_3");
browser.click("col_CUS_ATTR_USER_CAS_4");
browser.click("col_UNIQUE_ID");
browser.selectFrame("relative=up");
browser.click("//table[@id='tbl']/tbody/tr[6]/td/span[1]/span/span");
browser.waitForPageToLoad("30000");
browser.open("/aveksa/main?ReqType=GetPage&PageID=UserSummaryPage");*/
// Filtering for "last name = AveksaAdmin"
browser.click("//img[@title='Filter Data']");
browser.waitForPopUp("FilterDialogData", "50000");
assertTrue(browser.isElementPresent("//form[@id='MainForm']/table/tbody/tr/td"));
browser.selectWindow("FilterDialogData");
System.out.println("Filter options displayed");
assertTrue(browser.isElementPresent("lastName_OPERATOR"));
browser.select("lastName_OPERATOR", "value=EQUAL");
browser.type("lastName_VALUE", "AveksaAdmin");
browser.selectFrame("relative=up");
System.out.println("Filtering for Last Name value=AveksaAdmin");
browser.click("//table[@id='tbl']/tbody/tr[6]/td/span[1]/span/span");
// Refreshing Users tab to view the filtered data
browser.selectWindow("Aveksa - Unified Users");
browser.windowFocus();
assertTrue(browser.isElementPresent("UsersTab"));
browser.click("UsersTab");
browser.waitForPageToLoad("50000");
assertTrue(browser.isTextPresent("Rows 1 - 1 of 1"));
System.out.println("Filter successful"+ "\n" +"Rows 1 - 1 of 1 displayed");
// Removing the previous filter
assertTrue(browser.isElementPresent("//img[@title='Filter Data']"));
browser.click("//img[@title='Filter Data']");
browser.waitForPopUp("FilterDialogData", "50000");
assertTrue(browser.isElementPresent("//form[@id='MainForm']/table/tbody/tr/td"));
browser.selectWindow("FilterDialogData");
System.out.println("Filter options displayed again");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (browser.isElementPresent("lastName_OPERATOR")) break; } catch (Exception e) {}
//Thread.sleep(1000);
}
assertTrue(browser.isElementPresent("lastName_OPERATOR"));
browser.select("lastName_OPERATOR", "value=nullOp");
browser.selectFrame("relative=up");
System.out.println("Removed filter");
browser.click("//table[@id='tbl']/tbody/tr[6]/td/span[1]/span/span");
// Refreshing users tab again to view unfiltered data
browser.selectWindow("Aveksa - Unified Users");
browser.windowFocus();
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (browser.isTextPresent("Rows 1 - 10 of 75")) break; } catch (Exception e) {}
// Thread.sleep(1000);
}
//assertTrue(browser.isElementPresent("UsersTab"));
//browser.click("UsersTab");
//browser.waitForPageToLoad("50000");
//browser.refresh();
assertTrue(browser.isTextPresent("Rows 1 - 10 of 75"));
System.out.println("Filter removed"+ "\n" +"Rows 1 - 10 of 75 displayed");
// Filtering for "last name contains tony"
assertTrue(browser.isElementPresent("//img[@title='Filter Data']"));
browser.click("//img[@title='Filter Data']");
browser.waitForPopUp("FilterDialogData", "50000");
assertTrue(browser.isElementPresent("//form[@id='MainForm']/table/tbody/tr/td"));
browser.selectWindow("FilterDialogData");
System.out.println("Filter options displayed again");
assertTrue(browser.isElementPresent("lastName_OPERATOR"));
browser.select("lastName_OPERATOR", "label=contains");
browser.type("lastName_VALUE", "tony");
browser.selectFrame("relative=up");
System.out.println("Filtering for Last Name contains 'tony'");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (browser.isElementPresent("//table[@id='tbl']/tbody/tr[6]/td/span[1]/span/span")) break; } catch (Exception e) {}
//Thread.sleep(1000);
}
browser.click("//table[@id='tbl']/tbody/tr[6]/td/span[1]/span/span");
// Refreshing Users tab to view the filtered data
browser.selectWindow("Aveksa - Unified Users");
browser.windowFocus();
assertTrue(browser.isElementPresent("UsersTab"));
browser.click("UsersTab");
browser.refresh();
browser.waitForPageToLoad("50000");
assertTrue(browser.isTextPresent("Rows 1 - 2 of 2"));
System.out.println("Filter successful"+ "\n" +"Rows 1 -2 of 2 displayed");
// Removing the previous filter
assertTrue(browser.isElementPresent("//img[@title='Filter Data']"));
browser.click("//img[@title='Filter Data']");
browser.waitForPopUp("FilterDialogData", "50000");
assertTrue(browser.isElementPresent("//form[@id='MainForm']/table/tbody/tr/td"));
browser.selectWindow("FilterDialogData");
System.out.println("Filter options displayed again");
assertTrue(browser.isElementPresent("lastName_OPERATOR"));
browser.select("lastName_OPERATOR", "value=nullOp");
browser.selectFrame("relative=up");
System.out.println("Removed filter");
browser.click("//table[@id='tbl']/tbody/tr[6]/td/span[1]/span/span");
// Refreshing users tab again to view unfiltered data
browser.selectWindow("Aveksa - Unified Users");
browser.windowFocus();
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (browser.isTextPresent("Rows 1 - 10 of 75")) break; } catch (Exception e) {}
// Thread.sleep(1000);
}
//assertTrue(browser.isElementPresent("UsersTab"));
//browser.click("UsersTab");
//browser.waitForPageToLoad("50000");
//browser.refresh();
assertTrue(browser.isTextPresent("Rows 1 - 10 of 75"));
System.out.println("Filter removed"+ "\n" +"Rows 1 - 10 of 75 displayed");
assertTrue(browser.isElementPresent("//img[@title='Logout']"));
browser.click("//img[@title='Logout']");
System.out.println("Logout");
browser.waitForFrameToLoad("Aveksa - Logout", "30000");
System.out.println("Popup displayed");
browser.selectFrame("PopupIframe");
System.out.println("Select popup");
//assertTrue(browser.isElementPresent("//table[@id='tbl']/tbody/tr[6]/td/span[1]/span/span"));
browser.click("//table[@id='tbl']/tbody/tr[6]/td/span[1]/span/span");
System.out.println("Confirm Logout");
browser.waitForPageToLoad("30000");
} public void tearDown() {
browser.stop();
}
}
Appreciate you help.
Thanks
Niju
Submitted by mark0 on Thu, 2008-09-25 09:20.
Nice blog. I'm trying to add multiple tests to the main testcase. They all ran successfully, however, they ran in random order. Would anyone know how to get the tests to run sequentially?
[testng] [TestRunner] WILL BE RUN IN RANDOM ORDER:
[testng] [TestRunner] com.example.tests.main.MainTest_5()
[testng] [TestRunner] com.example.tests.main.MainTest_3()
[testng] [TestRunner] com.example.tests.main.MainTest_2()
[testng] [TestRunner] com.example.tests.main.MainTest_1()
[testng] [TestRunner] com.example.tests.main.MainTest_4()
[testng] [TestRunner] WILL BE RUN SEQUENTIALLY:
[testng] [TestRunner] ===
[testng] [TestRunner] Found 5 applicable methods
[testng] [Invoker 8568863] Invoking com.example.tests.main.MainTest_5
[testng] [Invoker 8568863] Invoking com.example.tests.main.MainTest_3
[testng] [Invoker 8568863] Invoking com.example.tests.main.MainTest_2
[testng] [Invoker 8568863] Invoking com.example.tests.main.MainTest_1
[testng] [Invoker 8568863] Invoking com.example.tests.main.MainTest_4
Thanks
Submitted by fenkner on Mon, 2008-10-06 15:30.
Yes, you can use the sequential attribute in the annotation.
@Test (sequential=true)
Submitted by mark0 on Tue, 2008-10-14 11:16.
Would the sequential attribute be defined in all of the @Test instances as below?
@AfterSuite(alwaysRun = true)
private void stopTest() {
selenium.stop();
}
@Test(sequential = true)
public void MainTest_1() throws Exception {
Selenium Tests;
}
@Test(sequential = true)
public void MainTest_2() throws Exception {
Selenium Tests;
}
@Test(sequential = true)
public void MainTest_3() throws Exception {
Selenium Tests;
}
It compiles and runs but still, not sequentially. Thought it may be the testNG version, so I tried using 5.8 with the same results.
Submitted by mark0 on Wed, 2008-10-15 07:59.
In the TestNG documentation, I found that the sequential attribute can only be used in the class level and will be ignored if used at the method level. Once I moved it to the class level, it's working as desired.
Thanks for the suggestion.
Submitted by davisn on Wed, 2008-10-15 15:14.
Try this
@Test(groups = {'Test_1" , sequential = true)
public void MainTest_1() throws Exception {
Selenium Tests;
@Test(groups = {'MainTest_2" , sequential = true)
........
for each test class
And, testng.xml file
..........................
........................
Submitted by davisn on Wed, 2008-10-15 15:53.
Correct the typo
@Test(groups = {'Test_1"} , sequential = true)
public void MainTest_1() throws Exception {
Selenium Tests;
@Test(groups = {'MainTest_2"} , sequential = true)
for each test class
And, testng.xml file
<suite .......>
<test name="MainTest_1">
<groups>
<run>
<include name="Test_1"/>
</run>
</group>
<classes>
<class name="com.......Test_1/>
</classes>
</test name>
<test name=....>
</test name>
</suite>
Submitted by mark0 on Thu, 2008-10-16 12:21.
When I added the sequential attribute after each of the @Test method lines, the test runs in Random order.
Only way to get the test to say that it is running sequentially is by adding the attribute before the class level, like...
@Test(sequential = true)
public class Main extends SeleneseTestCase {
... (@BeforeSuite and @AfterSuite ...
@Test(groups = {"Test_1" })
public void MainTest_1() throws Exception {
Selenium Tests;
}
@Test(groups = {"Test_1" })
public void MainTest_2() throws Exception {
Selenium Tests;
}
@Test(groups = {"Test_1" })
public void MainTest_3() throws Exception {
Selenium Tests;
}
}
When I run this, it reports
[testng] [TestRunner] WILL BE RUN IN RANDOM ORDER:
[testng] [TestRunner] WILL BE RUN SEQUENTIALLY:
[testng] [TestRunner] com.example.tests.main.MainTest_1()
[testng] [TestRunner] com.example.tests.main.MainTest_3()
[testng] [TestRunner] com.example.tests.main.MainTest_2()
[testng] [TestRunner] ====
Obviously, those are not in the sequential order.
Submitted by tester0123 on Fri, 2008-11-07 01:33.
Hi,
I tried executing my project after I did the setup, but i have got some.
Issue:
The script was trying to open the local host using 4848 port ans it was not available. Can you please help in this?
|
||
|
|