title: Best way to avoid timeout in Java Selenium TestNG when I have multiple tests in one class?
body: <p>I have multiple tests in one class in Selenium TestNG. Problem is that nearly every time I get some timeout exception in different test or in a different step in a test. So is hard to catch exact element causing the timeout.</p>
  
  <pre><code>org.openqa.selenium.ElementNotVisibleException: element not visible
  OR
  org.openqa.selenium.WebDriverException: unknown error: Element &lt;img data-aura-rendered-by="3:3231;a" src="avatar_96.png" class="profileTrigger branding-user-profile circular" alt="User" title="User"&gt; is not clickable at point (1887, 68). Other element would receive the click: &lt;div class="panel slds-modal slds-modal--large slds-fade-in-open" aria-labelledby="title_1233:319;a" tabindex="-1" role="dialog" aria-modal="true" data-aura-rendered-by="1249:319;a" style="opacity: 1;"&gt;...&lt;/div&gt;
  </code></pre>
  
  <p>What is the best way to avoid timeout in Selenium TestNG when I have multiple tests in one class?
  Is there some code which I can put for instance to </p>
  
  <pre><code>@BeforeClass or @Beforetest
  </code></pre>
  
  <p>Which will apply for all tests in the class?</p>
  
  <p>For a better understanding, I am sharing my code.</p>
  
  <pre><code> public class BothApprovalCockpitLighting   {
  
    private static WebDriver driver;
    public static WebDriverWait wd;
  
    @BeforeTest
    public void setUp()
    {
        System.out.println("*******************");
        System.out.println("launching Chrome browser");
        System.setProperty("webdriver.chrome.driver", "C:\\Drivers\\chromedriver_win32\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
  
    }
  
    @BeforeClass
    public void login() throws Exception
    {
         driver.get("https://test.com/"); 
  
         wd = new WebDriverWait(driver, 30);
          wd.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='username']")));
  
          // Enter username in textbox 
          System.out.println("Enter username in textbox"); 
          driver.findElement(By.xpath("//input[@id='username']")).sendKeys("USERNAME" ); //Batcon
  
  
          //Enter Password in texbox 
          System.out.println("Enter Password in texbox"); 
          driver.findElement(By.xpath("//input[@id='password']")).sendKeys("PASSWORD");
  
          //Click on Login button 
          System.out.println("Click on Login button"); 
          driver.findElement(By.xpath("//input[@id='Login']")).click(); 
  
          System.out.println("Login Sucessfully");
    }
  
    @Test(priority=1)
    public void test1DontCointainApprovalCockpit() throws Exception
    {
  
        driver.findElement(By.xpath("//img[@alt='All Tabs']")).click();
        String pageSource = driver.getPageSource();
  
        boolean b1 = pageSource.contains("Approval");
        boolean b2 = pageSource.contains("Cockpit");
  
  
        System.out.println("Page should not cointain - Approval Cockpit. This is a negative test.");
        System.out.println("Page cointain Approval: " + b1);
        System.out.println("Page cointain Cockpit: " + b2);
  
        if(b1 || b2)
        {
            System.out.println("Test 1 is fail - Page cointain Approval Cockpit.");
        }
        else
        {
            System.out.println("Test 1 is past - Page doesn´t cointain Approval Cockpit.");
        }
  
        Assert.assertFalse(b1,"Failed test 1 page cointain Approval");
        Assert.assertFalse(b2,"Failed test 1 page cointain Cockpit");
  
  
    }
  
    @Test(priority=2)
    public void test2SwitchCointain() throws Exception
    {
        String actualText1 =  driver.findElement(By.xpath("(//a[contains(text(),'Switch')])[2]")).getAttribute("innerHTML");
  
        Assert.assertTrue(actualText1.contains("Switch to Lightning Experience"), "Failed test 2 page doesn´t cointain Switch");
  
  
  
    }
  
    @Test(priority=3)
    public void test3Switch() throws Exception
    {
  
  
         driver.findElement(By.xpath("//*[text()[contains(.,'John')]]")).click();
         driver.findElement(By.linkText("Switch")).click();
  
    }
  
    @Test(priority=4)
    public void test4FMIRApprovalCokpit() throws Exception
    {
        driver.findElement(By.className("slds-icon-waffle")).click();
        String actualText1 =  driver.findElement(By.xpath("//*[text()[contains(.,'FIR')]]")).getAttribute("innerHTML");
  
  
  
        System.out.println("FIR text: " + actualText1);
  
  
  
        Assert.assertTrue(actualText1.contains("FMIR"), "Failed test 4 page doesn´t cointain FMIR");
  
    }
  
    @Test(priority=5)
    public void test4ApprovalCokpit() throws Exception
    {
  
  
        String actualText2 =  driver.findElement(By.xpath("//*[text()[contains(.,'Cockpit')]]")).getAttribute("innerHTML"); 
  
  
        System.out.println("Cockpit text:" + actualText2);
  
  
  
        Assert.assertTrue(actualText2.contains("Approval Cockpit"), "Failed test 4 page doesn´t cointain Cockpit");
  
  
  
    }
  
  
    @Test(priority=6)
    public void test6Link() throws Exception
    {
        driver.findElement(By.xpath("//img[@alt='FIR']")).click();
    }
  
    @Test(priority=7)
    public void test7backToSalesforce() throws Exception
    {
        Thread.sleep(10000);
        driver.findElement(By.xpath("//img[@alt='User']")).click();
        driver.findElement(By.linkText("Switch to Classic")).click();
    }
  
  
    @AfterClass
    public void backToClassic() throws Exception
    {
  
          //driver.findElement(By.xpath("//img[@alt='User']")).click();
          //driver.findElement(By.linkText("Switch to Classic")).click(); //Not working
  
    }
  
  
    @AfterTest
    public void tearDown()
    {
  
        if(driver!=null)
        {
            System.out.println("Closing Chrome browser");
            driver.quit();
        }
  
    }
  }
  </code></pre>