How to write Selenium Java Application code in IDE through main() and TestNG

前端 未结 2 1531
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-21 20:59

I m facing the below issue searched in Google couldn\'t find the clear answer how to resolve this.

Error :

org.apache.bcel.verifier.exc.Assertion         


        
相关标签:
2条回答
  • 2020-12-21 21:36

    The error is stemming out of org.apache.bcel.verifier

    You have to take care of a certain things as follows :

    Instead of using the ChromeDriver implementation use the WebDriver interface. chrome is a reserved keyword. Use some other user defined name for the method e.g. my_function() {} Simply defining public void chrome() won't execute your Test. You have to convert public void chrome() in to either of the following :

    • Convert into main() function as follows:

          public class Newtours  
          {
              public static void main(String[] args) 
              {
                  System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
                  WebDriver driver =  new ChromeDriver();
                  driver.get("http://newtours.demoaut.com/");
              }
          }
      
    • Integrate TestNG and add @Test annotations as follows :

          import org.openqa.selenium.WebDriver;
          import org.openqa.selenium.chrome.ChromeDriver;
          import org.testng.annotations.Test;
      
          public class Newtours 
          {
              @Test
              public void my_function()
              {
                  System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
                  WebDriver driver = new ChromeDriver();
                  driver.get("http://newtours.demoaut.com/");
              }
          }
      
    0 讨论(0)
  • 2020-12-21 21:55
    System.setProperty("webdriver.chrome.driver", "chromedriver");
    driver = new ChromeDriver(); 
    driver.get("http://newtours.demoaut.com/");
    

    Try this code it's working fine. I checked this and it's running fine. You need to give http or https for your url.

    0 讨论(0)
提交回复
热议问题