April 28, 2011

Enter data while script is running --Good example FOR loop and IF condition

Below script is good example for

1. How to enter data from key board while script is running..
2. Good example how to use FOR loop
3. How to use IF condition..


package test;

import javax.swing.JOptionPane;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.*;



public class Bidtest {
public Selenium selenium;
public SeleniumServer seleniumserver;

@Before
public void setUp() throws Exception {

seleniumserver = new SeleniumServer();
selenium = new DefaultSelenium("localhost", 4444, "*firefox","http://");
seleniumserver.start();
selenium.start();
}

@Test
public void testBidtest() throws Exception {

selenium.open("http://www.jeetle.in/");
selenium.windowMaximize();
selenium.click("link=Login");
selenium.waitForPageToLoad("30000");
selenium.type("edit-name", "Jyotish Varma Vegesna");
selenium.type("edit-pass", "jyotish44");
selenium.click("op");
selenium.waitForPageToLoad("30000");
selenium.click("//div[8]/div[1]/a/img");
selenium.waitForPageToLoad("30000");
// a text box will appear For entering data
String bidnum=JOptionPane.showInputDialog("Enter number of time u want to click Bid more");

int bidnum1=Integer.parseInt(bidnum);

for (int i = 1; i <= bidnum1; i++)
{
selenium.click("//img[@onclick='javascript:addMore1(1000)']");
}

// a text box will appear For entering data
String number=JOptionPane.showInputDialog("Enter number of rows you want to enter");

int num1=Integer.parseInt(number);
int  amount1 =0,amount2=0,amount3 =0;
for(int i = 1; i < num1; i++) {
amount3++;
if(amount3==10) {
amount2++;amount3=0;
if(amount2==10){
amount1++;amount2=0;
}
}
selenium.type("bid_amount1["+i+"]", ""+amount1);
selenium.type("bid_amount2["+i+"]", ""+amount2+amount3);
}

Thread.sleep(5000);
selenium.click("link=Logout");
selenium.waitForPageToLoad("30000");
}

@After
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();

}
}

No comments:

Post a Comment