A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeyfacebook.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 126
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: file_get_contents(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeyyoutube.cache): failed to open stream: No such file or directory
Filename: drivers/Cache_file.php
Line Number: 275
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 132
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Trying to access array offset on value of type bool
Filename: drivers/Cache_file.php
Line Number: 277
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 132
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeygoogle_site_verification.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 135
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeybanner_home.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 136
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeybanner_footer.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 137
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeymeta_title.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 141
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Config_model_SelectByKeymeta_description.cache): No such file or directory
Filename: drivers/Cache_file.php
Line Number: 279
Backtrace:
File: /home/anhtest2/public_html/application/core/MY_Model.php
Line: 25
Function: get
File: /home/anhtest2/public_html/application/models/Config_model.php
Line: 42
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 142
Function: SelectByKey
File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 9
Function: __construct
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
Tạo project Selenium Java và TestNG Framework với Maven trên IntelliJ IDE | Anh Tester
Nội
dung bài học
Cách cài đặt project Selenium Java và TestNG Framwork với Maven trên IntelliJ IDE.
✅ Tạo Maven project trên IntelliJ IDEA
Bước 1: Mở IntelliJ và chọn File > New > Project
Bước 2: Chọn tab New Project và nhập thông tin như mẫu🔆 Các bạn chú ý:
Số 4 chọn Maven
Số 6, 7 nhập gì cũng được. Không biết nhập gì thì nhập theo mẫu. Những thông tin này sẽ nằm trong file pom.xml sau khi create project.
Cuối cùng nhấn
Create là xong !!
✅ Cài đặt thư viện Selenium vào Maven project trên IntelliJ IDEA
Để cài đặt thư viện Selenium vào Maven project thì các bạn sẽ cài nó vào file pom.xml Thư viện sẽ được lấy tại đây: https://mvnrepository.com/ Chúng ta cần cái gì thì search cái đó rồi copy bỏ vào file pom.xml và build lại maven project là xong. 🔆 Ví dụ cài Selenium Khi dán vào pom.xml nhớ để trong cặp thẻ <dependencies> </dependencies>
Dán thư viện vào xong nhớ reload project lại bằng cách nhấn vào biểu tượng Reload hoặc right click > maven > reload project
🔆 Kiểm tra Selenium đã cài đặt vào maven project
Các bạn tạo 1 class bất kỳ ở package test (không tạo bên package main ) và nhập từ khoá WebDriver . Nếu nó gợi ý hiển thị lên như hình là đã cài đặt được Selenium thành công.
✅ Chạy code auto với Selenium
Để chạy được code mở Browser lên thì các bạn chỉ cần cài đặt thư viện mới nhất của Selenium (sau bản 4.11) là nó tự động tải về driver tương ứng với browser hiện tại trên máy tính của mình. Và cần cài thêm SLF4J hỗ trợ CDP với 2 loại API và Simple
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.11</version>
</dependency>
Để 2 thư viện trên vào sau chổ Selenium nhé. File pom.xml hiện tại như này:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.anhtester</groupId>
<artifactId>SeleniumMaven</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.17.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.11</version>
</dependency>
</dependencies>
</project>
Các bạn tạo 1 class ví dụ TestSelenium và dán đoạn code này vào:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.time.Duration;
public class TestSelenium {
public static void main(String[] args) {
//Khởi tạo browser với Chrome
WebDriver driver;
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
//Mở trang anhtester.com
driver.get("https://anhtester.com/");
//Click nút Login
driver.findElement(By.xpath("//a[@id='btn-login']")).click();
//Tắt browser
driver.quit();
}
}
Yeah ok. Còn về code auto test thì các buổi hôm sau An chỉ cho mọi người từng bước nhé 😋
✅ Cài đặt thư viện TestNG vào Maven project trên IntelliJ IDEA
Các bạn cũng add thư viện vào
pom.xml tương tự
Selenium nhé
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
</dependency>
Add xong nhớ nhấn
Reload Maven Project lại nhe.
Xong các bạn tạo class mới vào gọi ghi chú (Annotation)
@Test nếu nó hiện như hình bên dưới là ok.
Cộng đồng Automation Testing Việt Nam
🌱 Facebook
Fanpage: Anh Tester
🌱
Telegram Automation Testing:
Cộng đồng Automation Testing
🌱 Facebook Group Automation:
Cộng đồng Automation
Testing Việt Nam
🌱
Telegram Manual Testing:
Cộng đồng Manual Testing
🌱 Facebook
Group Manual:
Cộng đồng Manual Testing Việt Nam
Chia sẻ kiến thức lên trang
Bạn có thể đăng bài để chia sẻ kiến thức, bài viết
của chính bạn lên trang Anh Tester Blog
Anh Tester
facebook.com/anhtester
Đường dẫu khó chân vẫn cần bước đi
Đời dẫu khổ tâm vẫn cần nghĩ thấu