When I am calling method from another class at that time, WebDriver opens multiple Firefox window.
This is main class:
package selenium2Pack;
import java.sql.Date;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import selenium2Pack.loginPOI;
public class CounselorEducation {
static FirefoxDriver driver = new FirefoxDriver();
loginPOI xpath;
@Test
public void AddEducation() throws InterruptedException{
loginPOI.CounselorLogin();
Thread.sleep(10000);
//Click on Education tab
driver.findElement(By.xpath("html/body/div/div[2]/div/div/div/div[2]/div/div[1]/nav/ul/li[2]/a")).click();
Thread.sleep(5000);
//Click on AddNew button
driver.findElement(By.xpath("html/body/div/div[2]/div/div/div/div[2]/div/div[3]/div/div[1]/a/i")).click();
}
}
This is calling method:
package selenium2Pack;
import javax.swing.text.Document;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class loginPOI {
static FirefoxDriver driver = new FirefoxDriver();
static String firstName = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[1]/div[1]/input";
String Email,LastName,BrowseButton,Username,Password,ContactNo,Gender,DOB,Country,State,City,Street,Address,Marital_status,Logout,EducationTab;
static String RegisterURl = "http://192.163.222.186/~puzzlelife/development/#/register";
static String LoginURL = "http://192.163.222.186/~puzzlelife/development/#/login";
public void main() throws InterruptedException{
String firstName = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[1]/div[1]/input";
String LastName = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[1]/div[2]/input";
String BrowseButton = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[2]/div[1]/input[1]";
String Email = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[2]/div[2]/input";
String Username = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[3]/div[1]/input";
String Password = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[3]/div[2]/input";
String ContactNo = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[3]/div[2]/input";
String Gender = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[4]/div[2]/select";
String DOB = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[5]/div[1]/div/span/span";
String Country = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[5]/div[1]/div/span/span";
String State = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[6]/div[1]/select";
String City = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[6]/div[2]/select";
String Street = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[7]/div[1]/input";
String Address = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[7]/div[2]/textarea";
String Marital_status = "html/body/div/div[2]/div/div/div/div[2]/div/div/form/div[1]/div[8]/div/select";
String Logout = "html/body/div/header/div/div[3]/div/a[2]";
String EducationTab = "html/body/div/div[2]/div/div/div/div[2]/div/div[1]/nav/ul/li[2]/a";
}
public static void CounselorLogin() throws InterruptedException{
driver.get(LoginURL);
Thread.sleep(15000);
driver.findElement(By.id("username")).sendKeys("arun");
driver.findElement(By.id("password")).sendKeys("arun");
Thread.sleep(5000);
WebElement submit =driver.findElement(By.xpath("html/body/div/div[2]/div/div[2]/div/div/div[2]/div/form/button"));
submit.click();
Thread.sleep(5000);
String CurrentURL = driver.getCurrentUrl();
if(LoginURL.equals(CurrentURL))
System.out.println( "Un-Successful to login");
else
System.out.println("Successful to login");
Thread.sleep(10000);
}
public static void Logout() throws InterruptedException{
//Click on Logout Button
driver.findElement(By.xpath("html/body/div/header/div/div[3]/div/a[2]")).click();
Thread.sleep(5000);
//Check text on page
if(driver.getPageSource().contains("Login"))
System.out.println("Successfully Logout");
else
System.out.println("Un-Successfully Logout");
}
public static void DOB(){
}
}