Để chạy Selenium WebDriver trên trình duyệt Cốc Cốc bạn cần tải Chrome Driver & Cài đặt trình duyệt Cốc Cốc lên máy. Sau khi cài đặt xong, nhấp phải chuột vào biểu tượng Cốc Cốc, chọn Properties, mục Target chính là path của trình duyệt.
Các bước thực hiện:
B1: Khai báo đến Chrome Driver.
1 2 |
// Path to the ChromeDriver. System.setProperty("webdriver.chrome.driver","E:/SB-Selenium/libs/chromedriver_win32/chromedriver.exe"); |
B2: Khai báo đường dẫn trình duyệt Cốc Cốc.
1 2 3 |
// Path to the Coccoc browser. ChromeOptions options = new ChromeOptions(); options.setBinary("C:/Users/sangbui/AppData/Local/CocCoc/Browser/Application/browser.exe"); |
Sau khi thực hiện xong, bạn sẽ có một code hoàn chính như bên dưới để có thể chạy được test case trên Cốc Cốc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public class Coccoc_project { private WebDriver driver; @Before public void setUp() throws Exception { // Path to the ChromeDriver. System.setProperty("webdriver.chrome.driver", "E:/SB-Selenium/libs/chromedriver_win32/chromedriver.exe"); // Path to the Coccoc browser. ChromeOptions options = new ChromeOptions(); options.setBinary("C:/Users/sangbui/AppData/Local/CocCoc/Browser/Application/browser.exe"); driver = new ChromeDriver(options); } @Test public void testPage() throws Exception { driver.get("https://www.sangbui.com/"); Thread.sleep(5000); } } |
2 Comments