I have a session timeout problem like this:
I am using selenium + webdriver + java(junit)
While testing each(tab) test case of particular web page in one programme, i need first test Login button, after successfully login i need to click on button called "add device". Now my problem is when i click on "add device" Login page comes and says "session time out". Please help me...........Thanks in advance......
And Updated code is:
import java.io.File;
import java.util.List;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.ie.InternetExplorerDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
import com.thoughtworks.selenium.SeleneseTestBase;
public class NuemeraClass extends SeleneseTestBase {
private static WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
String str = null;
private boolean check = false;
@Before
public void setUp() throws Exception {
// System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
//driver = new ChromeDriver();
// DesiredCapabilities caps = new DesiredCapabilities();
//FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");
// WebDriver driver = new FirefoxDriver(firefoxProfile);
//DesiredCapabilities dc = DesiredCapabilities.firefox();
//driver = new InternetExplorerDriver();
driver = new FirefoxDriver();
baseUrl = "http://localhost:8080/";
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
}
@Test
public void testUntitled() throws Exception {
driver.get(baseUrl+"/Nuemera/promotional");
assertEquals("BLOCK MY PHONE - Registration Benefits",driver.getTitle());
/*Testing Benefits------starts*/
driver.findElement(By.linkText("Benefits")).click();
str = driver.findElement(By.xpath("//div[@class = 'benefits text-center no-mobile']/h1")).getText();
System.out.println(str);
assertEquals(str,"STOLEN? BLOCK IT NOW!");
/*Testing Benefits------ends*/
/*Testing FAQ------starts*/
driver.findElement(By.linkText("FAQ")).click();
str = driver.findElement(By.xpath("//div[@class = 'box faqheader']/h2")).getText();
System.out.println(str);
assertEquals(str,"Frequently Asked Questions");
// Thread.sleep(2000);
/*Testing FAQ------ends*/
File snapshot =((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
System.out.println(snapshot);
/*Testing Contact-------starts*/
driver.findElement(By.linkText("Contact")).click();
str = driver.findElement(By.xpath("//div[@class = 'box grey']/div/p")).getText();
System.out.println(str);
assertEquals(str,"Coming soon...");
//Thread.sleep(2000);
/*Testing Contact ------ends*/
/*Testing Login button--------starts*/
driver.findElement(By.linkText("Login")).click();
str = driver.findElement(By.xpath("//div[@id = 'loginDiv1']/form/a")).getText();
System.out.println(str);
assertEquals(str,"Sign In");
//Thread.sleep(2000);
/*Testing Login button--------ends*/
/*Testing successfully Login or Not------starts*/
driver.findElement(By.id("userId")).clear();
driver.findElement(By.id("userId")).sendKeys("[email protected]");
driver.findElement(By.id("pwd")).clear();
driver.findElement(By.id("pwd")).sendKeys("xxx");
driver.findElement(By.xpath("//div[@id = 'loginDiv1']/form/a")).click();
str = driver.findElement(By.xpath("//div[@class = 'container']/nav/ul/li[6]/a")).getText();
System.out.println(str);
assertEquals(str,"[email protected] Log Out");
/*Testing successfully Login or Not------ends*/
driver.findElement(By.xpath("//div[@id = 'deviceList']/div/div/div/div/a")).click();
driver.findElement(By.xpath("//div[@class = 'fancybox-skin']/a")).click();
Thread.sleep(2000);
System.out.println("done");
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
/*@AfterClass
public void testAfterClass() throws Exception{
}*/
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}