title: I want to run different classes particular method from TestNG but everytime it opens a new window when i include beforeclass in each class
body: <p>I want to run different classes particular method from TestNG but everytime it opens a new window when i include beforeclass in each class so i have now excluded beforeclass from add and logout classes so it can use same browser to run rest methods but its not working</p>
  
  <p>The first class is of login class which is as below</p>
  
  <pre class="lang-java prettyprint-override"><code>public class LoginWeb {
      public WebDriver driver;
      WebDriverWait wait;
      LoginScreen loginExcel;
      @BeforeClass
      public void beforeClass (){
          System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
          driver=new ChromeDriver();
          driver.manage().window().maximize();
          driver.get("http://10.7.1.180/views/index.html#/login");
          System.out.println(driver.getTitle());
      }
  
      @Test (description = "Valid Credentials!")
      public void LoginWithValidWebExcelEmailAndPass() throws IOException, BiffException  {
          loginExcel= new LoginScreen(driver);
          FileInputStream fi = new FileInputStream("D:\\Programs\\New\\Sourcesmartdata.xls");
          Workbook w = Workbook.getWorkbook(fi);
          Sheet s = w.getSheet(0);
          int z = s.getRows();
          System.out.println("no of rows------------------------:"+z);
          String email = s.getCell(0, 1).getContents();
          System.out.println("Email -----------------"+email);
          loginExcel.EnterEmail(email);
          String password= s.getCell(1, 1).getContents();
          System.out.println("Password------------------- "+password);
          loginExcel.EnterPassword(password);
          loginExcel.ClickToLogin();
          wait= new WebDriverWait(driver, 10);
          WebElement GetLogo = wait.until(ExpectedConditions.visibilityOf(loginExcel.TopRightMenu));
          String str= GetLogo.getText();
          System.out.println("Text------------"+str);
          Assert.assertEquals(str, "Source Smart");  
      }
  }
  </code></pre>
  
  <p>The second class is of adding commodities here i have excluded beforeclass as if i include before class it opens a new window and here login script is not written</p>
  
  <pre class="lang-java prettyprint-override"><code>public class AddCommoditiesWeb{
      WebDriver driver;
      WebDriverWait wait;
      AddCommodities addcommodity;
  
      @Test (description="Add Multiple Commodities!")  
      public void AddMultipleNewCommodities () throws Exception, Exception{
          addcommodity = new AddCommodities(driver);
          addcommodity.MenuCommodities();     //click left menu to open manage commodities page
          FileInputStream fi = new FileInputStream("D:\\Programs\\New\\Sourcesmartdata.xls");
          Workbook w = Workbook.getWorkbook(fi);
          Sheet s = w.getSheet(1);
          int z=s.getRows();
          System.out.println("no of rows------------------------:"+z);
          for(int row=1; row &lt;2; row++){
              Thread.sleep(5000);
              addcommodity.ClickAddCommodities();  // click add commodity button
              String commodityname = s.getCell(0, row).getContents();
              System.out.println("commodityname -----------------"+commodityname);
              //enterdefinecommodityTxtBox.sendKeys(commodityname);
              addcommodity.Enterdefinecommodity(commodityname);
              String grade= s.getCell(1, row).getContents();
              System.out.println("grade------------------- "+grade);
              //entergradeTxtBox.sendKeys(grade);
              String unit= s.getCell(2, row).getContents();
              System.out.println("unit------------------- "+unit);
              //enterunitTxtBox.sendKeys(unit);
              String minprice= s.getCell(3, row).getContents();
              System.out.println("min price------------------- "+minprice);
              //enterminpriceTxtBox.sendKeys(minprice);
              String maxprice= s.getCell(4, row).getContents();
              System.out.println("max price------------------- "+maxprice);
              //entermaxpriceTxtBox.sendKeys(maxprice);
              addcommodity.EnterAddCommoditiesData(grade,unit,minprice,maxprice);
          }
          wait=new WebDriverWait(driver,10);
          WebElement commodityname= wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div[4]/div/section[2]/div[4]/d-expand-collapse[1]/div/div/div[1]/h4/a")));        
          String commoditynamejustadded= commodityname.getText();
          System.out.println("name--------------"+commoditynamejustadded);
          assertEquals(commoditynamejustadded, "Rice");
      }
  }
  </code></pre>
  
  <p>TestNG code:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  &lt;suite name="Suite"&gt;
    &lt;test name="Login check"&gt;
      &lt;classes&gt;
        &lt;class name="SourceSmartWeb.LoginWeb"/&gt;
        &lt;class name = "SourceSmartWeb.AddCommoditiesWeb"&gt;
        &lt;methods&gt;
        &lt;include name="AddMultipleNewCommodities"/&gt;
        &lt;/methods&gt;
        &lt;/class&gt;
        &lt;class name ="SourceSmartWeb.LogoutWeb"/&gt;
      &lt;/classes&gt;
    &lt;/test&gt; &lt;!-- Test --&gt;
  &lt;/suite&gt; &lt;!-- Suite --&gt;
  </code></pre>
  
  <p>Logout class:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class LogoutWeb{
      WebDriver driver;
      //  @BeforeClass
      //  public void beforeClass (){
      //      System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
      //      driver=new ChromeDriver();
      //      driver.manage().window().maximize();
      //      driver.get("http://10.7.1.180/views/index.html#/login");
      //      System.out.println(driver.getTitle());
      //      super.beforeClass();
      //          
      //  }
  
  
      @Test                                                                                                       
      public void Logout() throws InterruptedException {
          LogoutScreen logout=new LogoutScreen(driver);
          logout.ClickToLogout();
      }
  
      @AfterClass
      public void exit(){
          driver.quit();
      }
  }
  </code></pre>
  
  <p>What its doing is it opens the browser logins and then do nothing. How can i make it do rest of activities on same browser as if i add before class in second class it opens a new browser and then there i dont have login code. please guide</p>