Return types clarification
resolves
: the function is asynchronous and returns a Promise which resolves to the value
returns
: the function is synchronous and returns the value
The local folder with static html files you wish to test. This folder is used both by browserstack-local and the static webserver.
If you dont use either of those, the files will be loaded through the file://
protocol.
boolean (default: false
)
If tue then information logging eg by static server and xvfb wont show
boolean (default: true
)
Whether a Xvfb server should be started.
Is automatically set to false
for headless browsers or when using a provider
object (default: undefined
)
An object in the form { width, height }
where width & height define the window size. Can be overridden by setWindow
function (default: undefined
)
This function is called after a page is opened and receives the webpage
instance as argument.
It should return or resolve to an object which is used in the page proxy
boolean / object
If an object the configuration for the included static webserver. If true
then the default configuration will be used.
host
(string, defaultlocalhost
)
The hostname / ip to run the static server on. Optionally you can also set theHOST
env variable.port
(integer, default3000
)
The port the static server should run on. Optionally you can also set thePORT
env variable.folder
(string, optional)
The path used as the webroot for the webserver. If not provided the defaultfolder
browser config option is used
object
This configuration is only used with browserstack/local browsers
The object can list the following properties:
start
(boolean, defaulttrue
)
Whether to start the browserstack-local daemon onbrowser.start
stop
(boolean, defaulttrue
)
Whether to stop the browserstack-local daemon onbrowser.close
user
(string)
Your browserstack user name
for security reasons it is recommended to use the env var
BROWSERSTACK_USER
instead
key
(string)
Your browserstack key
for security reasons it is recommended to use the env var
BROWSERSTACK_KEY
instead
folder
(string, boolean optional)
The path to the folder which should be accessible through the browserstack-local tunnel. Explicitly set this tofalse
if you wish to test an internal server. If any other falsy value is provided the defaultfolder
browser config option is used.
arguments
- config (type:
object
)
arguments
- capabilities (type:
string
) - ...arguments (type:
any
)
resolves this
rejects on error
Starts the browser and all extra commands
For Puppeteer capabilities are added as launch options and arguments to the args
key of launch options
For Selenium arguments are ignored
returns boolean
Returns true when the browser was started succesfully
resolves void
Closes the browser and all commands that were started
arguments
- path (type:
string
) returnsurl
Returns the full url for a path. Depending your browser config it returns the url to/for browserstack-local, static server or just local files.
arguments
- url (type:
string
) - readyCondition? (type:
string
|Function
)
resolves page proxy
(see below)
rejects on error
Opens the url on a new webpage in the browser and waits for the readyCondition to become true.
It resolves to a Proxy which returns properties in the following order:
- a
userExtended
property (see configuration options) - a Webpage property (from tib)
- a Page property (from the BrowserDriver, Puppeteer only)
- a BrowserDriver property
If the requested property doesnt exist on any of the internal objects it returns undefined
Also see the webpage:property
hook which is called every time you access a property through the Proxy
arguments
- capabilities? (type
object
)
returns object
Returns the current capabilities. If the capabilities
argument is specified these capabilities are also returned but are not added to the current capabilities.
arguments
- capabilities (type
object
)
returns this
Adds to or sets the current capabilities with the new capabilities
arguments
- capability (type
string
)
returns string
Returns the value for the requested capability
arguments
- key (type
string
) - value (type
string
)
returns this
Adds or sets the value of the capability with name key
arguments
- width (type
number
) - height (type
number
)
Sets the window size.
Also used for the Xvfb comamand
returns string
Returns the browser name
arguments
- browserName (type
string
)
Dont call this unless you have to, if you use a browserstring the browser name should already be set correctly
Sets the browser name
returns this
If called the browser will be started headless (if supported). Disables the Xvfb command
returns string
this capability is probably only usefull when using a provider or selenium server
Returns the browser version which was set
arguments
- version (type
string
)
returns this
this capability is probably only usefull when using a provider or selenium server
Sets the browser version
arguments
- name (type
string
) - version (type
string
)
returns this
this capability is probably only usefull when using a provider or selenium server
Sets the os name and os version
browser.setOs('windows', 7)
arguments
- version (type
string
)
returns this
this capability is probably only usefull when using a provider or selenium server
Sets the os version
browser.setOs('windows') // default
browser.setOsVersion(7)
arguments
- name (type
string
)
returns this
this capability is probably only usefull when using a provider or selenium server
Sets the name of the device (eg for mobile testing)
arguments
- path (type
string
)
This method is only available in BrowserStackLocal browsers
Returns the full url for the relative path
so browserstack can access your code through the browserstack-local tunnel
resolves string
The full html of the loaded Webpage
resolves string
Resolves the document title of the loaded Webpage
arguments
- selector (type:
string
)
resolves ASTElement
Retrieves the html from the matched element and parses the returned outerHTML with htmlCompiler
to return the corresponding ASTElement
arguments
- selector (type:
string
)
resolves Array<ASTElement>
Retrieves the html from matched elements and parses the returned outerHTML with htmlCompiler
to return an array of the corresponding ASTElement
s
arguments
- selector (type:
string
)
resolves number
Retrieves the number of elements found
arguments
- selector (type:
string
)
resolves string
Retrieves the outerHTML for the matched element
arguments
- selector (type:
string
)
resolves Array<string>
Retrieves an array with the outerHTML of all matched elements
arguments
- selector (type:
string
) - attribute (type:
string
)
resolves string
Retrieves the value of the attribute for the matched element
arguments
- selector (type:
string
) - attribute (type:
string
)
resolves Array<string>
Retrieves an array of the attribute values for the matched elements
arguments
- selector (type:
string
) - trim (type:
boolean
)
resolves string
Retrieves the textContent
for the matched element. If trim is true the textContent will be trimmed
arguments
- selector (type:
string
) - trim (type:
boolean
)
resolves Array<string>
Retrieves an array with the textContent
of all matched elements. If trim is true the textContent's will be trimmed
arguments
- selector (type:
string
)
resolves void
Calls click on the matched element
arguments
- pageFunction (type:
Function
) - ...arguments (type:
any
)
returns any
Executes the synchronous pageFunction in the loaded webpage context. The pageFunction is parsed to a string using @babel/parser
, then transpiled with @babel/core/transform
for the specified browser version*. The function is reconstructed on the webpage using new Function
.
If you need to pass arguments from your test scope to the pageFunction, pass them as additional arguments to runScript. Make sure to only pass serializable variables (e.g. a Function is not).
It returns whatever pageFunction
returns
*Please note that the syntax is transpiled but polyfills are not added automatically. Polyfills need to be already loaded on the webpage. In other words, dont use features in your test pageFunctions which you dont also use in production
arguments
- pageFunction (type:
Function
) - ...arguments (type:
any
)
returns any
Does the same as runScript
but pageFunction can be asynchronous
Called before any browser dependency is loaded
Called immediately after all browser dependencies are loaded
Called before the browser is started
passed arguments
- driver (type:
object
, the browser driver instance)
When starting the browser failed this hook will not be called
Called immediately after the browser has started
Called before the browser is closed
Called immediately after the browser was closed
Called before a new browser page is opened
passed arguments
- page (type:
object
, the page instance)
Called immediately after a new browser page is instantiated, but before navigation occures* and before the wait condition is triggered.
*On puppeteer, on selenium instantiating and navigating arent separate actions
passed arguments
- page (type:
object
, the page instance)
Called immediately after a new browser page was opened
passed arguments
- property (type:
string
)
Called whenever a property from the page proxy is requested.
passed arguments
- builder (type:
object
, the Selenium builder instance)
Called just before the build is called on the Selenium builder to start the browser
passed arguments
- options (type:
array
) - builder (type:
object
, the Selenium builder instance)
Called just before browser specific options are applied