Severity: Warning
Message: unlink(/home/anhtest2/public_html/application/cache/Category_model_SelectMainMenu.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/Category_model.php
Line: 53
Function: query_cache
File: /home/anhtest2/public_html/application/core/MY_Controller.php
Line: 106
Function: SelectMainMenu
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
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: 144
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
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/User_model.php
Line: 234
Function: query_cache
File: /home/anhtest2/public_html/application/controllers/frontend/Post.php
Line: 38
Function: SelectById
File: /home/anhtest2/public_html/index.php
Line: 315
Function: require_once
import com.google.common.util.concurrent.Uninterruptibles;
import org.openqa.selenium.By;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.HasDevTools;
import org.openqa.selenium.devtools.v110.network.Network;
import org.openqa.selenium.devtools.v110.network.model.Headers;
import org.testng.annotations.Test;
import java.time.Duration;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class HandleAuthentication extends BaseTest {
@Test
public void handleAuthentication() {
// Authentication username & password
String url = "https://the-internet.herokuapp.com/basic_auth";
String username = "admin";
String password = "admin";
// Get the devtools from the running driver and create a session
DevTools devTools = ((HasDevTools) driver).getDevTools();
devTools.createSession();
// Enable the Network domain of devtools
devTools.send(Network.enable(
Optional.of(100000),
Optional.of(100000),
Optional.of(100000))
);
String auth = username + ":" + password;
// Encoding the username and password using Base64 (java.util)
String encodeToString = Base64.getEncoder().encodeToString(auth.getBytes());
// Pass the network header -> Authorization : Basic <encoded String>
Map<String, Object> headers = new HashMap<>();
headers.put("Authorization", "Basic " + encodeToString);
devTools.send(Network.setExtraHTTPHeaders(new Headers(headers)));
// Load the application url
driver.get(url);
Uninterruptibles.sleepUninterruptibly(Duration.ofSeconds(3));
String successFullyLoggedInText = driver.findElement(By.xpath("//p")).getText();
System.out.println(successFullyLoggedInText);
}
}
Source code on GitHub:
https://github.com/anhtester/NewFeatureSelenium4/blob/main/src/test/java/HandleAuthentication.java
Anh Tester
Đườ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