0

I have created three classes in TestNG and every time that I run my test.xml file it is then opening up multiple instance of IE.

I need to do the the following activity in single browser instance :- Launch IE>>Open URL>>Login To Application>>Search Task.............. As of now by my code it is opening three instance of IE.

Class FirstClass

package com;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;

public class FirstClass

{
    public static WebDriver driver=null;
  @Test

  public void Login() throws InterruptedException {
      driver.findElement(By.id("loginForm:loginName")).clear();
      driver.findElement(By.id("loginForm:loginName")).sendKeys("nishant");
      driver.findElement(By.id("loginForm:password")).clear();
      driver.findElement(By.id("loginForm:password")).sendKeys("test1234");
      Select dropdown=new Select(driver.findElement(By.id("loginForm:cabinetMenu")));
      dropdown.selectByVisibleText("neonsit");

      driver.findElement(By.id("loginForm:buttonlogin")).click();
      Thread.sleep(5600);


  }
  @BeforeMethod
  public void beforeMethod() {


      System.setProperty("webdriver.ie.driver","C:\\Test\\IEDriverServer_Win32_2.45.0\\IEDriverServer.exe");

       driver = new InternetExplorerDriver();
       driver.get(BaseVariable.baseURL);

  }

  @AfterMethod
  public void afterMethod() {
      //driver.quit();
  }

}

Class QuickSearch

package com;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.BeforeClass;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

import com.BaseVariable;
import com.FirstClass;
import com.Login;
import com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const;

public class TestQuickSearch  extends FirstClass {

@Test
public void  QuickSearchByReg_ID () throws InterruptedException {
    driver.findElement(By.id("loginName")).sendKeys("EC*");
    Thread.sleep(5000);
    Select dd = new Select(driver.findElement(By.id("quickSrchProcess")));
    dd.selectByValue("1");
    driver.findElement(By.id("buttonGo")).click();
}


}

closed as unclear what you're asking by DEnumber50, Paul Muir, Yu Zhang, Kate Paulk, IAmMilinPatel Nov 10 '16 at 2:41

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Voting to close this because there is no question being asked. – DEnumber50 Nov 9 '16 at 15:42
0

This is because when you call the Class TestQuickSearch extends FirstClass it initiates the FirstClass before TestQuickSearch since there is a @BeforeMethod and you have two test method (1 test method in each class) the IE browser is initiated twice.

Also show us the TestNG.xml code.

  • <suite name="Test - Suite" > <test name="NeonLogin"> <classes> <class name="com.FirstClass" /> <class name="com.TestQuickSearch"/> </classes> </test> </suite> this is my testng class......... So Alok can you please tell if i want to do the above functionality at one go Like :- Opening browser>>Login to Application>>>then Search the task using TestQucikSearch Class .. what i need to do – satish Nov 10 '16 at 4:46
  • one of the ways would be to have all the methods in 1 class. – Alok Nov 10 '16 at 5:56
  • Bring all the methods in one class and then initiate and close the browser using '@BeforeTest' (to open the browser) '@AfterTest' (to close the browser) '@Test(priority = 0)' to Login. '@Test(priority = 1)' to do the quick search. – Alok Nov 10 '16 at 6:18
  • Ok.....thanks... then if i have to do multiple task Like add user/add task etc then i have to create separate class for each and in each class i need to do BeforeTest' (to open the browser) 'AfterTest' (to close the browser) 'Test(priority = 0)' to Login then @test method for work i need to do...Please answer............ – satish Nov 10 '16 at 6:36
  • Hi @alok please suggest a better way of doing this – satish Nov 10 '16 at 9:38
0

I do not even know what testNG is, but one thing struck me about your post. In your AfterMethod you are not closing IE via a call to driver.quit. You have commented this out. In your BeforeMethod you are opening a new instance of IE. So it looks like the behavior you describe is expected.

@BeforeMethod
  public void beforeMethod() {


      System.setProperty("webdriver.ie.driver","C:\\Test\\IEDriverServer_Win32_2.45.0\\IEDriverServer.exe");

       driver = new InternetExplorerDriver();
       driver.get(BaseVariable.baseURL);

  }

  @AfterMethod
  public void afterMethod() {
      //driver.quit();
  }

On a final point, you didn't actually ask a question. Can you edit your post to actually ask a question?

Not the answer you're looking for? Browse other questions tagged or ask your own question.