Ова секција описује Zabbix додатке за JavaScript језик имплементиран са Duktape-ом за употребу у скрипти [Browser item] (/manual/config/items/itemtypes/browser). Ови додаци допуњују JavaScript објекте описане на страници [Додатни JavaScript објекти] (/manual/config/items/preprocessing/javascript/javascript_objects).
The Browser
object manages WebDriver sessions, initializing a session upon creation and terminating it upon destruction. A single script can support up to four Browser
objects.
To construct a Browser
object, use the new Browser(options)
syntax. The options
(JSON object) parameter specifies browser options, usually the WebDriver options method result (for example, Browser.chromeOptions()
).
The following methods are supported with the Browser
object.
Method | Description |
---|---|
navigate(url) |
Navigate to the specified URL. Parameters: url - (string) URL to navigate to. |
getUrl() |
Return a string of the opened page URL. |
getPageSource() |
Return a string of the opened page source. |
findElement(strategy, selector) |
Return an Element object with one element in the opened page (or return null if no elements match strategy and selector ).Parameters: strategy - (string, CSS selector/link text/partial link text/tag name/Xpath) Location strategy;selector - (string) Element selector using the specified location strategy. |
findElements(strategy, target) |
Return an array of Element objects with multiple elements in the opened page (or return an empty array if no elements match location strategy and target).Parameters: strategy - (string, CSS selector/link text/partial link text/tag name/Xpath) Location strategy;target - (string) Element selector using the specified location strategy. |
getCookies() |
Return an array of Cookie objects. |
addCookie(cookie) |
Set cookies. Parameters: cookie - (Cookie object) Cookie to set. |
getScreenshot() |
Return a string (base64 encoded image) of browser's viewport. |
setScriptTimeout(timeout) |
Set script loading timeout. Parameters: timeout - (integer) Timeout value (in milliseconds). |
setSessionTimeout(timeout) |
Set session (page load) timeout. Parameters: timeout - (integer) Timeout value (in milliseconds). |
setElementWaitTimeout(timeout) |
Set element location strategy (implicit) timeout. Parameters: timeout - (integer) Timeout value (in milliseconds). |
collectPerfEntries(mark) |
Collect performance entries to retrieve with the getResult() method.Parameters: mark - (string, optional) performance snapshot mark. |
getRawPerfEntries() |
Return an array of performance entry objects. |
getResult() |
Return a Result object with browser session statistics (error information, performance snapshots, etc.). |
getError() |
Return a BrowserError object with browser errors (or return null if there are no browser errors). |
setError(message) |
Set a custom error message to be included in the Result object.Parameters: message - (string) Error message. |
discardError() |
Discard the error to be returned in the Result object. |
getAlert() |
Return an Alert object with browser alerts (or return null if there are no browser alerts). |
chromeOptions() |
Return a chromeOptions object with predefined Chrome browser options. |
firefoxOptions() |
Return a firefoxOptions object with predefined Firefox browser options. |
safariOptions() |
Return a safariOptions object with predefined Safari browser options. |
edgeOptions() |
Return an edgeOptions object with predefined Edge browser options. |
All Browser methods can throw the following errors:
BrowserError
- derived from the Error
object that is thrown if the Browser
constructor fails; contains an additional browser
property with a Browser
object that threw this BrowserError
.WebdriverError
- derived from BrowserError
; contains the same properties as the BrowserError
object, which indicate if the error was generated in response to an error in the WebDriver response.Објекат Element
се враћа од стране Browser
објекта методама findElement()
/findElements()
и не може се директно конструисати.
Објекат Element
представља елемент на веб страници и обезбеђује методе за интеракцију са њим.
Следеће методе су подржане са објектом Element
.
Method | Description |
---|---|
getAttribute(name) |
Враћа вредност атрибута атрибута елемента (или враћа null ако наведени атрибут није пронађен).Параметри: name - (стринг) Име атрибута. |
getProperty(name) |
Враћа вредност својства елемента (или враћа null ако наведени атрибут није пронађен).Параметри: name - (стринг) Назив својства. |
getText() |
Враћа стринг текстуалне вредности текста елемента. |
click() |
Кликните на елемент. |
clear() |
Очистити садржај елемента који се може уређивати. |
sendKeys(keys) |
Шаље кључеве. Параметри: keys - (стринг) Кључеви за слање. |
Објекат Cookie
враћа метод getCookies()
објекта Browser
и прослеђује се методи addCookie()
.
Иако објекат Cookie
нема методе, може да садржи следећа својства:
Property | Type | Description |
---|---|---|
name | string | Назив колачића. |
value | string | Вредност колачића. |
path | string | Путања за коју је колачић важећи. Подразумевано је "/" ако се изостави приликом додавања колачића. |
domain | string | Домен за који је колачић видљив. Подразумевано је URL домен активног документа тренутног контекста прегледања сесије ако се изостави приликом додавања колачића. |
secure | boolean | Означава да ли је колачић безбедан. Подразумевано је false ако се изостави приликом додавања колачића. |
httpOnly | boolean | Означава да ли је колачић само за HTTP. Подразумевана вредност је false ако се изостави приликом додавања колачића. |
expiry | integer | Време истека колачића (у секундама од Unix Epoch). Не сме се подесити ако се изостави приликом додавања колачића. |
sameSite | string | Атрибут sameSite колачића, који контролише да ли колачић треба да буде ограничен на контекст прве стране или истог сајта.Може се подесити на "Lax" или "Strict" .Подразумевана вредност је "None" ако се изостави приликом додавања колачића. |
Објекат Alert
представља упозорење веб странице, враћа га метода getAlert()
објекта Browser
и не може се директно конструисати.
Објекат Alert
садржи својство text
са текстом упозорења (или null
ако нема упозорења).
Следеће методе су подржане са објектом Alert
.
Method | Description |
---|---|
accept() |
Прихвата упозорење. |
dismiss() |
Одбацује упозорење. |
The Result
object contains session statistics and is returned by the Browser
object getResult()
method.
Typically, the Result
object is stringified and returned from the script, and then parsed into dependent item values through preprocessing.
While the Result
object does not have any methods, it can contain the following properties.
Property | Type | Description | ||
---|---|---|---|---|
duration | string | Session duration from session creation to result retrieval. | ||
error | object | Error information. | ||
http_status | integer | HTTP status returned by the WebDriver (or 0 if there are no WebDriver errors). | ||
error_code | string | Error returned by the WebDriver (or empty string if there are no WebDriver errors). | ||
message | string | WebDriver error message (or empty string if there are no WebDriver errors). | ||
performance_data | object | Performance statistics. | ||
summary | object | Performance summary. | ||
navigation | object | Navigation summary. | ||
resource | object | Resource summary. | ||
details | array of objects | Performance statistics after each operation that could have resulted in navigation. | ||
mark | string | (optional) Performance snapshot mark specified with the collectPerfEntries() method. |
||
navigation | object | Navigation statistics. | ||
resource | object | Resource summary for this step. | ||
user | array of objects | Array of mark/measure type statistics. | ||
marks | array of objects | Marked performance snapshot indexes. | ||
name | string | Performance snapshot mark name. | ||
index | integer | Performance snapshot index in details array. |