- 필수 기능
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- 디지털 경험
- 소프트웨어 제공
- 보안
- 로그 관리
- 관리
- 인프라스트럭처
- ci
- containers
- csm
- ndm
- otel_guides
- overview
- slos
- synthetics
- tests
- 워크플로
This guide describes how you can test a user interface (UI) using custom JavaScript in a browser test. JavaScript assertions support synchronous and asynchronous code.
To create an assertion using custom JavaScript:
For more information about assertions, see Browser Test Steps.
To verify that an element with a specific ID is not on the page, use return !document.getElementById("<ELEMENT_ID>");
.
To verify that elements are not on the page and return the number of elements in the console error, add the following in the body assertion:
var element = document.querySelectorAll("<SELECTORS>");
if ( element.length > 0 ){
console.error(element.length+" "+"elements exist");
}
return element.length === 0;
Your browser test results contain console.error
logs.
To verify that a radio button is checked, use return document.querySelector("<SELECTORS>").checked = true;
in the body assertion.
To set the value of a specified local storage item, add the following in the body assertion:
localStorage.setItem(keyName, keyValue);
return true
For example, to set the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC to “mytime”:
localStorage.setItem("mytime", Date.now());
return true
You can use an external library to test the content of a rendered PDF.
To load external libraries, use a promise in the body assertion:
Custom JavaScript
const script = document.createElement('script');
script.type = 'text/javascript';
//load external library
script.src = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.min.js";
const promise = new Promise((r) => script.onload = r)
document.head.appendChild(script)
await promise
var loadingTask = pdfjsLib.getDocument("<PDF_URL>");
return await loadingTask.promise.then(function(pdf) {
return pdf.getPage(1).then(function(page) {
return page.getTextContent().then(function(content) {
return content.items[0].str.includes("<CONTENT_STRING>")
})
})
});
Additional helpful documentation, links, and articles: