Thursday, July 12, 2012



To verify the Text from Source code in selenium : 


package zipQuoteNavigation;

import com.thoughtworks.selenium.*;

import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.*;

import static org.testng.Assert.*;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
import zipQuoteNavigation.SendFileEmail;

public class Compuquotes {
public Selenium selenium;
public SeleniumServer seleniumserver;
SendFileEmail e = new SendFileEmail();

@BeforeClass
public void setUp() throws Exception
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome","http://www.loan.com");
selenium.start();
}

@Test
public void test() throws Exception{


BufferedReader in=null;
InputStreamReader inputStream =null;
try{
inputStream = new InputStreamReader (new FileInputStream("C:\\Documents and Settings\\sgainewar\\workspace\\HQF\\src\\zipQuoteNavigation\\urls.csv"));
in =new BufferedReader(inputStream);
String line = null;
String url ="";
while ((line = in.readLine())!=null)
{
String[] data = line.split(",");
if(data.length >= 1){
url = data[0];
System.out.println("url : "+ url );
selenium.deleteCookie("", "");
Thread.sleep(500);
selenium.open(url);
Thread.sleep(4000);
selenium.waitForPageToLoad("30000");
selenium.click("id=zipCode");
selenium.type("id=zipCode", "94154");
selenium.click("id=fs-index-submit");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (selenium.getHtmlSource().matches("^[\\s\\S]*in_frame[\\s\\S]*$")) break; } catch (Exception e) {}
Thread.sleep(1000);


}
}
}
}
catch (Exception e){
e.printStackTrace();
}
finally{
try{
if(in!=null){
in.close();
}
if(inputStream !=null){
inputStream.close();
}
}
catch(Exception e){
e.printStackTrace();
}
}

}
@AfterClass
public void tearDown() throws Exception{
selenium.stop();
Thread.sleep(2000);
e.main(null);
}
}



No comments:

Post a Comment