Jacobvu84 / selenium-vietnam-training-course

Questions Tracking
7 stars 5 forks source link

Lỗi khi chạy Run TestNG #21

Closed linhptt closed 6 years ago

linhptt commented 6 years ago

Mình mới viết 1 đoạn code ngắn đơn giản để mở FF lên nhưng khi run thì bị lỗi này, mọi người giúp mình với nhé:

[Utils] Problem creating output directory C:\Users\Linhptt3\workspace\AI_2\test-output\old\Default suite [Utils] Attempting to create C:\Users\Linhptt3\workspace\AI_2\test-output\old\Default suite\toc.html [Utils] Directory C:\Users\Linhptt3\workspace\AI_2\test-output\old\Default suite exists: true [Utils] Problem creating output directory C:\Users\Linhptt3\workspace\AI_2\test-output\old\Default suite [Utils] Attempting to create C:\Users\Linhptt3\workspace\AI_2\test-output\old\Default suite\Default test.properties [Utils] Directory C:\Users\Linhptt3\workspace\AI_2\test-output\old\Default suite exists: true

caodangtinh commented 6 years ago

@linhptt : Bạn có thể cho mình xem đoạn code (bao gồm cả đoạn khai báo WebDriver), mình nghĩ vấn dề do việc khai báo trùng WebDriver

linhptt commented 6 years ago

đây bạn:

package MBOT;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class NhapCH {
    public static WebDriver driver;
    public static String baseUrl;

    @BeforeTest
    public void before(){

        driver=new FirefoxDriver();
        baseUrl="file:///D:/Project/AI_Voice/Tong%20hop%20cau%2 0hoi/MB%20Bank%20Demo_v2/MB%20Bank%20Demo.html";

        }
    @Test
     public void openWeb(){
    driver.get(baseUrl);

    } 
}
linhptt commented 6 years ago

Chính xác thì chỗ Error log nó ghi như này bạn ạ: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property;

Jacobvu84 commented 6 years ago

@linhptt Bạn sửa lại tên thư mục Driver EXE thành DriverEXE. và thử lại. Đồng thời xóa cái thử mục test-output trước khi chạy lại nhé.

Em có dùng maven để chay không ? Hay chạy trực tiếp trên Eclipse ?

linhptt commented 6 years ago

Chỗ Driver EXE mình thử bỏ đi thì kết quả vẫn thế bạn ạ:

package MBOT; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;

public class NhapCH { public static WebDriver driver; public static String baseUrl;

@BeforeTest
public void before(){

    driver=new FirefoxDriver();
    baseUrl="file:///D:/Project/AI_Voice/Tong%20hop%20cau%2 0hoi/MB%20Bank%20Demo_v2/MB%20Bank%20Demo.html";
//  driver.get(baseUrl);
    }
@Test
 public void openWeb(){
driver.get(baseUrl);

} 

}

Jacobvu84 commented 6 years ago

@linhptt Giữ nguyên code cũ và SỬA LẠI TÊN THƯ MỤC không phải xóa nó đi. Xóa cái thư mục test-output.

Sao new Firefox mà lại dùng IEDriverServer.exe ?

Jacobvu84 commented 6 years ago
@BeforeTest
public void before(){
        System.setProperty("webdriver.gecko.driver", ".\\driver\\geckodriver.exe");
    driver=new FirefoxDriver();
    baseUrl="xxxxxx";
    }

@Test
 public void openWeb(){
     driver.get(baseUrl);
} 

Bạn tạo một thư mục tên là driver trong thư mục dự án và download geckodriver.exe bỏ vào đó. Đảm bảo rằng FF version mới nhất.

Còn nếu muốn chạy với trình duyệt IE. Thì download cái IEDriverServer bỏ vào thư mục driver và chạy đoạn code này

public void before(){
        System.setProperty("webdriver.ie.driver", ".\\driver\\IEDriverServer.exe");
    driver=new InternetExplorerDriver();
    baseUrl="xxxxxx";
    }

@Test
 public void openWeb(){
     driver.get(baseUrl);
} 
linhptt commented 6 years ago

Mình đang muốn chạy FF bạn ạ, mình sửa thành như này được ko:

package MBOT; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;

public class NhapCH { public static WebDriver driver; public static String baseUrl;

@BeforeTest
public void before(){

    System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
    driver=new FirefoxDriver();
    baseUrl="file:///D:/Project/AI_Voice/Tong%20hop%20cau%2 0hoi/MB%20Bank%20Demo_v2/MB%20Bank%20Demo.html";
    }
@Test
 public void openWeb(){
driver.get(baseUrl);

} 

}

Jacobvu84 commented 6 years ago

@linhptt Ad nghĩ là không? Nó phải trỏ tới bản driver binary. không phải file chạy của Firefox. Bạn nên tham khảo đoạn code phía trên

caodangtinh commented 6 years ago

@linhptt : mục đích của đoạn setProperty là bạn đang đang set cho property webdriver.gecko.driver trỏ đến đường dẫn của gecko driver, như vậy giá trị của nó phải trỏ đến file geckodriver.exe, ở ví dụ bên trên a @vuthelinh đang để file geckodriver.exe trong thư mục driver cùng thư mục dự án nên đường dẫn sẽ là .\driver\geckodriver.exe. Nhưng theo mình để thuận tiện nhất thì bạn có 2 cách :

  1. Bạn thêm config webdriver.gecko.driver=PATH_TO_GECKO vào file senerity.properties
  2. Lúc chạy chương trình bằng command line bạn truyền tham số -Dwebdriver.gecko.driver = PATH_TO_GECKO khi chạy
Jacobvu84 commented 6 years ago

@caodangtinh Bạn ấy mới đang học chạy kịch bản auto với TestNG. Không có liên quan tới serenity trong chương trình học của lớp đào tạo đâu em

linhptt commented 6 years ago

Được rồi các bạn ạ, do cái gecko của mình bản cũ quá =)) Cảm ơn các bạn nhiều nhiều nhé