Nội dung bài viết
Tham khảo cách setup môi trường Selenium Java trên hệ điều hành MAC/ Linux:
- Cài đặt/ cấu hình Selenium Java và Eclipse (MAC OS)
- Cài đặt/ cấu hình Selenium Java và Eclipse (Ubuntu Linux)
Cài đặt Java JDK
- Recommend nên dùng Java version 1.8 hoặc 1.11
- Download trên trang chủ: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- Nếu các bạn ngại đăng kí tài khoản trên Oracle thì tải file cài đặt Offline: https://drive.google.com/drive/folders/1iCTMnWFQzMrMoN2ZSZxHl4dDuIhnqztO
- Trong này mình đã để sẵn các file Offline: Java/ Eclipse/ Firefox/ Selenium/ Driver
- Sau khi tải về -> cài đặt bình thường -> click Next -> Install cho đến khi hoàn tất
- Sau khi cài đặt xong bật command line (cmd) kiểm tra version đã cài đặt thành công
- java -version
Cài đặt Eclipse IDE
- Link download: https://www.eclipse.org/downloads/packages/release/, tùy vào hệ thống của bạn phiên bản 32/64 bit để lựa chọn cho phù hợp. Chọn bản Eclipse IDE for Java Developer là đáp ứng đủ cho nhu cầu công việc.
Tải về thư viện Selenium
- Link download: http://selenium-release.storage.googleapis.com/index.html?path=2.53/
- Chọn và tải: selenium-server-standalone-2.53.1.jar
Tạo dự án Java
- Xả nén Elipse IDE > chạy eclipse.exe từ bước 2 đã tải về
- Tạo 1 thư mục ngang hàng vs thư mục eclipse – đặt tên là my_work_space
- Set workspace – mục đích để nếu cài đặt lại hệ thống thì eclipse sẽ tự load lại các dự án/tùy chọn bạn đã làm việc trước đó – ko cần phải cài đặt lại
- Tạo mới Project: File > New > Java Project > [Đặt tên Project] > Finish
- Project name: Selenium Tutorials
- Tạo mới Package: Right click vào thư mục src > New > Package > [Đặt tên Package] >Finish
- Package name: automationfc.com
- Tạo mới Class: Right click vào Package > New > Class > [Đặt tên Class] > Finish
- Class name: Topic_01_Check_Environment
Thêm thư viện Selenium vào dự án
- Tạo mới 1 thư mục trong project để lưu trữ các java library hoặc browser driver cần dùng
- Đặt tên thư mục là lib
- Copy thư viện selenium-server-standalone-2.53.1.jar từ bước 03 ở trên dán vào thư mục lib
- Click chuột phải vào thư viện và Add vào Build Path
Cài đặt TestNG plugin vào Eclipse
- Chọn Help > Install New Software
- Nhập:
- Name = TestNG
- Location = https://testng.org/testng-eclipse-update-site/6.14.3/
- Click Add
- Click vào Select All và nhấn Next button
- Click “I accept the terms of the license agreement” và nhấn Finish button
- Nếu hiện ra 1 popup thông báo về Security Warning, nhấn OK để tiếp tục
- Hoàn thành, click Yes để khởi động lại Eclipse
- Sau khi khởi động xong, cần kiểm tra TestNG đã được cài đặt thành công: Window > Preferences
- TestNG plugin đã được tích hợp vào Eclipse
Chạy thử Testcase
- Copy và Paste toàn bộ vào Class <Topic_01_Check_Environment> đã tạo
package automationfc.com; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class Topic_01_Check_Environment { WebDriver driver; @BeforeClass public void beforeClass() { driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get("http://demo.guru99.com/v4/"); } @Test public void TC_01_ValidateCurrentUrl() { String loginPageUrl = driver.getCurrentUrl(); Assert.assertEquals(loginPageUrl, "http://demo.guru99.com/v4/"); } @Test public void TC_02_ValidatePageTitle() { String loginPageTitle = driver.getTitle(); Assert.assertEquals(loginPageTitle, "Guru99 Bank Home Page"); } @Test public void TC_03_LoginFormDisplayed() { Assert.assertTrue(driver.findElement(By.xpath("//form[@name='frmLogin']")).isDisplayed()); } @AfterClass public void afterClass() { driver.quit(); } }
Xử lí lỗi
- Nếu gặp báo error thì import thư viện vào bằng cách hover vào hàm bị báo lỗi và import đúng thư viện cần thiết
- Run testcase
- Click chuột phải vào Class test chọn Run As > TestNG Test
- Kết quả sau khi run pass
Chào anh,
em làm theo đúng trình tự nhưng khi chạy nó báo lỗi như vầy
Exception in thread “main” java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 7 more
anh có thể chỉ em cách khắc phục ko? Cảm ơn.
Bạn gửi đoạn code lên mình check thử nhé.
sao ko hiên trình duyệt trên firefox vậy
Mô tả lỗi rõ chút nhé:
– Push code lên
– Chụp hình lỗi
– Lỗi hiển thị có message như thế nào.
Em chào anh ạ. Anh cho em hỏi, ver firefox nào thì tương thích với selenium 2.53.1 này ạ? Em run test mà nó báo version k phù hợp ạ. Em cảm ơn anh nhiều ạ.
Version 47 em. Em download bản offline ở đây rồi cài đè lên version hiện tại, cài xong tắt chế độ tự động Update đi nhé.
Hì hì. Nó hoạt động được rồi ạ. em cảm ơn anh ạ.
Vâng ạ. em cảm ơn anh nhiều ạ.
Code của em:
package org.webdriver.demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
@Test
public class LoginTest{
public void testLoginWithBlankField() {
System.setProperty(“webdriver.gecko.driver”, “geckodriver”);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(“marionette”, true);
WebDriver driver = new FirefoxDriver();
}
}
Bị lỗi này ạ, anh giúp em với
FAILED: testLoginWithBlankField
org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:30775 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
Build info: version: ‘3.5.2’, revision: ‘10229a9020’, time: ‘2017-08-21T17:54:21.164Z’
System info: host: ‘Les-Mac-mini.local’, ip: ‘fe80:0:0:0:1450:b47f:23f2:b317%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.12.5’, java.version: ‘1.8.0_144’
Driver info: driver.version: FirefoxDriver
E đổi lại ntn nhé:
public class LoginTest{
WebDriver driver
@Test
public void testLoginWithBlankField() {
System.setProperty(“webdriver.gecko.driver”, “geckodriver”);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(“marionette”, true);
driver = new FirefoxDriver();
}
}
của e lỗi như này là sao ạ??
[code language=”java” autolinks=”true”]
[RemoteTestNG] detected TestNG version 6.9.9
[TestNG] Running:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
in app-system-defaults
1519397642592 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi
1519397642593 addons.xpi DEBUG Existing add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} in app-global
1519397642593 addons.xpi DEBUG getInstallState changed: false, state: {}
Unable to read VR Path Registry from C:\Users\Thuy\AppData\Local\openvr\openvrpaths.vrpath
[Parent 8456, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
Unable to read VR Path Registry from C:\Users\Thuy\AppData\Local\openvr\openvrpaths.vrpath
[Child 13044, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 13044, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
1519397656403 addons.xpi DEBUG Calling bootstrap method shutdown on [email protected] version 1.1
1519397656404 addons.xpi DEBUG Calling bootstrap method shutdown on [email protected] version 76.1
1519397656406 addons.xpi DEBUG Calling bootstrap method shutdown on [email protected] version 25.0.0
1519397656427 addons.xpi DEBUG Calling bootstrap method shutdown on [email protected] version 1.0
1519397656428 addons.xpi DEBUG Calling bootstrap method shutdown on [email protected] version 1.0
1519397656429 addons.xpi DEBUG Calling bootstrap method shutdown on [email protected] version 0.9.6
1519397656431 addons.xpi DEBUG Calling bootstrap method shutdown on [email protected] version 1.0.5
1519397656432 addons.xpi DEBUG Calling bootstrap method shutdown on [email protected] version 2.0
1519397656432 addons.xpi DEBUG Calling bootstrap method shutdown on [email protected] version 2018.01.04.0062-4997c81d
###!!! [Parent][MessageChannel] Error: (msgtype=0x8000D,name=PBackgroundIDBDatabase::Msg_Invalidate) Channel error: cannot send/recv
[Parent 8456, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
Unable to read VR Path Registry from C:\Users\Thuy\AppData\Local\openvr\openvrpaths.vrpath
[Child 10676, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
1519397658288 addons.manager DEBUG shutdown
1519397658289 addons.manager DEBUG Calling shutdown blocker for XPIProvider
1519397658289 addons.xpi DEBUG shutdown
1519397658289 addons.xpi-utils DEBUG shutdown
1519397658290 addons.manager DEBUG Calling shutdown blocker for LightweightThemeManager
1519397658290 addons.manager DEBUG Calling shutdown blocker for GMPProvider
1519397658290 addons.manager DEBUG Calling shutdown blocker for PluginProvider
1519397658291 addons.manager DEBUG Calling shutdown blocker for PreviousExperimentProvider
1519397658297 addons.manager DEBUG Async provider shutdown done
*** UTM:SVC TimerManager:registerTimer called after profile-before-change notification. Ignoring timer registration for id: telemetry_modules_ping
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:112)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at ntt.wordpress.com.TestClass_01_WebDriver_Demo.beforeClass(TestClass_01_WebDriver_Demo.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:170)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
FAILED CONFIGURATION: @BeforeClass beforeClass
[/code]
Lỗi này em cập nhật lại browser firefox là được nhé, install bản Firefox 47.0.2 là được.
Em run nó mở firefox version mới nhất ra newtab, sau đó nó văng. Bản Firefox 47.0.2 nằm trong thư mục “C:\Program Files (x86)” còn bản mới nằm trong “C:\Program Files”
[code language=”java” autolinks=”true”]
[RemoteTestNG] detected TestNG version 6.9.9
[TestNG] Running:
C:\Users\Minh Minh\AppData\Local\Temp\testng-eclipse–186588125\testng-customsuite.xml
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
463818 addons.manager DEBUG Registering shutdown blocker for GMPProvider
1528897463818 addons.manager DEBUG Provider finished startup: GMPProvider
1528897463818 addons.manager DEBUG Starting provider: PluginProvider
1528897463818 addons.manager DEBUG Registering shutdown blocker for PluginProvider
1528897463818 addons.manager DEBUG Provider finished startup: PluginProvider
1528897463819 addons.manager DEBUG Completed startup sequence
Unable to read VR Path Registry from C:\Users\Minh Minh\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\Minh Minh\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\Minh Minh\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\Minh Minh\AppData\Local\openvr\openvrpaths.vrpath
1528897466242 addons.repository DEBUG No addons.json found.
1528897466262 addons.manager DEBUG Starting provider: PreviousExperimentProvider
1528897466262 addons.manager DEBUG Registering shutdown blocker for PreviousExperimentProvider
1528897466262 addons.manager DEBUG Provider finished startup: PreviousExperimentProvider
1528897466400 addons.xpi-utils DEBUG XPI Database saved, setting schema version preference to 24
1528897466593 addons.xpi INFO Mapping [email protected] to C:\Users\Minh Minh\AppData\Local\Temp\anonymous6552026905029719281webdriver-profile\extensions\[email protected]
1528897466593 addons.xpi DEBUG Ignoring file entry whose name is not a valid add-on ID: C:\Users\Minh Minh\AppData\Local\Temp\anonymous6552026905029719281webdriver-profile\extensions\webdriver-staging
1528897466594 addons.xpi DEBUG Existing add-on [email protected] in app-profile
1528897466595 addons.xpi INFO Mapping [email protected] to C:\Program Files\Mozilla Firefox\browser\features\[email protected]
1528897466595 addons.xpi INFO Mapping [email protected] to C:\Program Files\Mozilla Firefox\browser\features\[email protected]
1528897466595 addons.xpi INFO Mapping [email protected] to C:\Program Files\Mozilla Firefox\browser\features\[email protected]
1528897466595 addons.xpi INFO Mapping [email protected] to C:\Program Files\Mozilla Firefox\browser\features\[email protected]
1528897466595 addons.xpi INFO Mapping [email protected] to C:\Program Files\Mozilla Firefox\browser\features\[email protected]
1528897466595 addons.xpi INFO Mapping [email protected] to C:\Program Files\Mozilla Firefox\browser\features\[email protected]
1528897466596 addons.xpi INFO Mapping [email protected] to C:\Program Files\Mozilla Firefox\browser\features\[email protected]
1528897466596 addons.xpi INFO Mapping [email protected] to C:\Program Files\Mozilla Firefox\browser\features\[email protected]
1528897466596 addons.xpi DEBUG Existing add-on [email protected] in app-system-defaults
1528897466597 addons.xpi DEBUG Existing add-on [email protected] in app-system-defaults
1528897466598 addons.xpi DEBUG Existing add-on [email protected] in app-system-defaults
1528897466599 addons.xpi DEBUG Existing add-on [email protected] in app-system-defaults
1528897466599 addons.xpi DEBUG Existing add-on [email protected] in app-system-defaults
1528897466600 addons.xpi DEBUG Existing add-on [email protected] in app-system-defaults
1528897466600 addons.xpi DEBUG Existing add-on [email protected] in app-system-defaults
1528897466601 addons.xpi DEBUG Existing add-on [email protected] in app-system-defaults
1528897466602 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi
1528897466602 addons.xpi DEBUG Existing add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} in app-global
1528897466603 addons.xpi DEBUG getInstallState changed: false, state: {}
Unable to read VR Path Registry from C:\Users\Minh Minh\AppData\Local\openvr\openvrpaths.vrpath
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:112)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at minh.wordpress.com.TestClass_01_WebDriver_Demo.beforeClass(TestClass_01_WebDriver_Demo.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:170)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
[/code]
Em cài 1 bản firefox thôi nhé, gỡ các bản khác ra, nếu dùng selenium 2.xx thì dùng firefox = 48 nhé.
Nếu mới làm/ học thì em xài như trên a suggest là firefox 47.0.2, cài xong tắt chế độ auto update của firefox đi, sử dụng selenium-server-standalone 2.53.1 là chạy được.
Em chạy được rồi, cám ơn a nhiều ạ 🙂
Location = http://beust.com/eclipse-old/eclipse_6.9.10.201512240000
Link này hết hoạt động rồi giờ mình install bằng gì vậy a.
Thay thế bằng link này nhé: https://dl.bintray.com/testng-team/testng-eclipse-release/6.14.3/
e bị lỗi này ạ, e có cài firefox bản 48.0 cũng lỗi, sau gỡ cài bản 47 cũng lỗi
[code language=”java” autolinks=”true”]
[RemoteTestNG] detected TestNG version 6.14.3
org.testng.TestNGException:
Cannot instantiate class automation.com.Topic_01_Check_Environment
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:30)
at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:423)
at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:336)
at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:125)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:190)
at org.testng.TestClass.getInstances(TestClass.java:95)
at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:81)
at org.testng.TestClass.init(TestClass.java:73)
at org.testng.TestClass.(TestClass.java:38)
at org.testng.TestRunner.initMethods(TestRunner.java:389)
at org.testng.TestRunner.init(TestRunner.java:271)
at org.testng.TestRunner.init(TestRunner.java:241)
at org.testng.TestRunner.(TestRunner.java:192)
at org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33)
at org.testng.remote.support.RemoteTestNG6_12$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_12.java:66)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:713)
at org.testng.SuiteRunner.init(SuiteRunner.java:260)
at org.testng.SuiteRunner.(SuiteRunner.java:198)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1295)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1273)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:24)
… 25 more
Caused by: java.lang.Error: Unresolved compilation problem:
The type org.openqa.selenium.remote.RemoteWebDriver cannot be resolved. It is indirectly referenced from required .class files
at automation.com.Topic_01_Check_Environment.(Topic_01_Check_Environment.java:1)
… 30 more
[/code]
Em check thử các môi trường sau xem đúng ko nhé:
– Selenium 2.53.1
– Chrome mới nhất
– Chrome driver mới nhất
– Firefox bản 47.0.2
– Khi khởi tạo driver chỉ cần new FirefoxDriver() lên là dc – ko cần GeckoDriver
Ví dụ: driver = new FirefoxDriver();
Nếu ko được nữa thì add Skype a check giúp cho em.
Em chào anh,
Hiện tại em mới bắt đầu học Selenium em đang gặp lỗi này, anh hỗ trợ giúp em với ạ
Selenium version:3.141.59
chromedriver:85.0.4183.38
geckodriver: v0.27.0
public class login {
private WebDriver driver;
@Test
public void TestCase1_OpenWeb() {
// Mở website
driver.get("https://www.google.com/");
}
@BeforeMethod
public void beforeMethod() {
// Khởi tạo trình duyệt Firefox
System.setProperty("webdriver.gecko.driver", "F:\\project_java\\Browser\\geckodriver.exe");
driver = new FirefoxDriver();
}
@AfterMethod
public void afterMethod() {
// Đóng trình duyệt
driver.quit();
}
Em check lại đúng version mới nhất của trình duyệt Firefox là được nhé.
hi anh ,
Em gặp lỗi mong a giúp đỡ ạ, em mới bắt đầu học selenium và gặp lỗi như này ạ.Rất mong được anh giúp đỡ
11:02:11.977 INFO [GridLauncherV3.parse] – Selenium server version: 3.141.59, revision: e82be7d358
11:02:12.141 INFO [GridLauncherV3.lambda$buildLaunchers$3] – Launching a standalone Selenium Server on port 4444
2020-08-13 11:02:12.305:INFO::main: Logging initialized @724ms to org.seleniumhq.jetty9.util.log.StdErrLog
11:02:12.669 INFO [WebDriverServlet.] – Initialising WebDriverServlet
11:02:12.786 ERROR [BaseServer.start] – Port 4444 is busy, please choose a free port and specify it using -port option
em tìm hiểu mấy chỗ mà k hiểu vì sao. em cũng đã làm theo anh nhưng vẫn không được :((( em bị miss chỗ nào k ta