Kaixa commands
Methods
(static) launchLTIUsingToken(accessToken, courseIdopt, appNameopt)
Log into Canvas using an access token
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
accessToken |
String | the user's access token | ||
courseId |
int |
<optional> |
courseId from profile
|
the Canvas ID of the course to launch from |
appName |
String |
<optional> |
appName from profile
|
the name of the app as it appears in the course's left-hand nav |
assertAbsent(item, messageopt)
Make sure an element does not exist
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
TestObject | String | the TestObject or CSS selector | ||
message |
String |
<optional> |
generated message
|
a human-readable message to display if the test fails |
assertAbsentWithContents(contents, selector, messageopt)
Make sure an element with specific contents does not exist
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
contents |
String | the contents to search for | ||
selector |
String | a CSS selector corresponding to the item | ||
message |
String |
<optional> |
generated message
|
a human-readable message to display if the test fails |
assertDoesNotHaveClass(item, className, messageopt)
Make sure an element does not have a specific class name
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
TestObject | String | the TestObject or CSS selector of interest | ||
className |
String | the name of the class to expect | ||
message |
String |
<optional> |
generated message
|
a human-readable message to display if the test fails |
assertExists(item, messageopt, gracePeriodSecsopt)
Make sure an element exists
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
TestObject | String | the TestObject or CSS selector | ||
message |
String |
<optional> |
generated message
|
a human-readable message to display if the test fails |
gracePeriodSecs |
int |
<optional> |
10
|
the number of seconds to wait before throwing an error |
assertExistsWithContents(contents, selector, messageopt, gracePeriodSecsopt)
Make sure an element with specific contents exists
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
contents |
String | the contents to search for | ||
selector |
String | a CSS selector corresponding to the item | ||
message |
String |
<optional> |
generated message
|
a human-readable message to display if the test fails |
gracePeriodSecs |
int |
<optional> |
10
|
the number of seconds to wait before throwing an error |
assertFalse(value, messageopt)
Make sure an expression evaluates to false
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
boolean | the value that should be false | ||
message |
String |
<optional> |
unknown
|
a human-readable message to display if the test fails |
assertHasClass(item, className, messageopt)
Make sure an element has a specific class name
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
TestObject | String | the TestObject or CSS selector of interest | ||
className |
String | the name of the class to expect | ||
message |
String |
<optional> |
generated message
|
a human-readable message to display if the test fails |
assertNumElements(selector) → {Integer}
Get number of elements
Parameters:
Name | Type | Description |
---|---|---|
selector |
String | a CSS selector corresponding to the item |
Returns:
the number of elements on the page
- Type
- Integer
assertNumElements(selector, num)
Assert a certain number of elements
Parameters:
Name | Type | Description |
---|---|---|
selector |
String | a CSS selector corresponding to the item |
num |
Integer | the precise number of elements expected |
assertTrue(value, messageopt)
Make sure an expression evaluates to true
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
boolean | the value that should be true | ||
message |
String |
<optional> |
unknown
|
a human-readable message to display if the test fails |
chooseFile(item, filePath)
Choose a file for a file chooser
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector of the select element |
filePath |
String | the path of the file |
chooseSelectByLabel(item, label)
Choose an item in a select element based on its label
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector of the select element |
label |
String | the label to select in the dropdown |
chooseSelectByValue(item, value)
Choose an item in a select element based on its value
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector of the select element |
value |
String | the value of the item to select in the dropdown |
click(item, timeoutSecopt, dontScrollToopt)
Click an element
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
TestObject | String | the TestObject or CSS selector of interest | ||
timeoutSec |
int |
<optional> |
10
|
the number of seconds to wait before timing out |
dontScrollTo |
boolean |
<optional> |
if true, do not scroll to the element |
clickByContents(contents, selector)
Click an item by defining its contents
Parameters:
Name | Type | Description |
---|---|---|
contents |
String | the contents to search for |
selector |
String | a CSS selector corresponding to the item |
closeWindow()
Close the current window/tab
convertToTestObject(obj) → {TestObject}
Convert a Selenium WebElement into a TestObject
Parameters:
Name | Type | Description |
---|---|---|
obj |
WebElement | the element to convert |
Returns:
the corresponding object
- Type
- TestObject
convertToWebElement(obj) → {WebElement}
Convert a TestObject into a Selenium WebElement
Parameters:
Name | Type | Description |
---|---|---|
obj |
TestObject | the object to convert |
Returns:
the corresponding element
- Type
- WebElement
descendantOf(item, selector) → {TestObject}
Get the first descendant of an element that matches the selector
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector of the parent |
selector |
String | the selector to use to search for the descendant |
Returns:
child element
- Type
- TestObject
done()
Close the browser
elementAbsent(item) → {boolean}
Check if an element does not exist
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector |
Returns:
true if the element does not exist on the page
- Type
- boolean
elementExists(item) → {boolean}
Check if an element exists
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector |
Returns:
true if the element exists on the page
- Type
- boolean
elementWithContentsAbsent(contents, selector) → {boolean}
Check if an element with specific contents does not exist
Parameters:
Name | Type | Description |
---|---|---|
contents |
String | the contents to search for |
selector |
String | a CSS selector corresponding to the item |
Returns:
true if the element does not exist on the page
- Type
- boolean
elementWithContentsExists(contents, selector) → {boolean}
Check if an element with specific contents exists
Parameters:
Name | Type | Description |
---|---|---|
contents |
String | the contents to search for |
selector |
String | a CSS selector corresponding to the item |
Returns:
true if the element exists on the page
- Type
- boolean
ensureTestObject(item) → {TestObject}
Make sure an item is a TestObject. If it is a CSS selector, turn it into a TestObject
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector |
Returns:
a TestObject
- Type
- TestObject
exitWithError(message)
Exit with an error
Parameters:
Name | Type | Description |
---|---|---|
message |
String | a human-readable message to display |
extractDataFromClass(item, classPrefix) → {String}
Extract info from a class
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector of the element |
classPrefix |
String | the prefix of the class. Example: if there is a class "Event-12345" then with classPrefix "Event-" the return of this function would be "12345" |
Returns:
value following the prefix
- Type
- String
extractDataFromClassByContents(contents, selector, classPrefix) → {String}
Extract info from a class
Parameters:
Name | Type | Description |
---|---|---|
contents |
String | the contents to search for |
selector |
String | a CSS selector corresponding to the item |
classPrefix |
String | the prefix of the class. Example: if there is a class "Event-12345" then with classPrefix "Event-" the return of this function would be "12345" |
Returns:
value following the prefix
- Type
- String
find(selector) → {TestObject}
Given a CSS selector, find the TestObject
Parameters:
Name | Type | Description |
---|---|---|
selector |
String | the css selector to search for |
Returns:
the item
- Type
- TestObject
findByContents(contents, selector) → {TestObject}
Given the contents and a CSS selector for an element, find the TestObject
Parameters:
Name | Type | Description |
---|---|---|
contents |
String | the contents of the object. NOTE: must be the contents of the element, not contents of a child element! |
selector |
String | a css selector for the element Supported css selectors: All Elements: null or "*" All P Elements: "p" All Child Elements of p: "p > *" Element By ID: "#foo" Element By Class: ".foo" Element With Attribute: "*[title]" First Child of P: "p > *:first-child" Next Element after P: "p + *" |
Returns:
the matching object
- Type
- TestObject
findByXPath(xPath) → {TestObject}
Given an XPATH selector, find the TestObject
Parameters:
Name | Type | Description |
---|---|---|
xPath |
String | the xpath selector to search for |
Returns:
the item
- Type
- TestObject
findChildOfAncestor(args) → {TestObject}
Find an element by traversing the element tree: from the start element,
traverse up the tree to the specified ancestor and then back down
any number of levels to the first matching child
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Map | all arguments in one map
Properties
|
Returns:
element
- Type
- TestObject
getAttribute(item, attribute) → {String}
Get an attribute of an element
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector |
attribute |
String | the name of the attribute to get |
Returns:
value of the attribute
- Type
- String
getContentsXPath(contents, selector) → {String}
Get an xpath for finding an element based on a css selector and contents
Parameters:
Name | Type | Description |
---|---|---|
contents |
String | the contents of the object |
selector |
String | a css selector for the element Supported css selectors: All Elements: null or "*" All P Elements: "p" All Child Elements of p: "p > *" Element By ID: "#foo" Element By Class: ".foo" Element With Attribute: "*[title]", "a[title='foo']" First Child of P: "p > *:first-child" Next Element after P: "p + *" |
Returns:
xpath to use to find the element
- Type
- String
getCurrentDay() → {int}
Get the current day
Returns:
day
- Type
- int
getCurrentMonth() → {int}
Get the current month
Returns:
month
- Type
- int
getCurrentYear() → {int}
Get the current year
Returns:
year
- Type
- int
getDateString() → {String}
Get the current date as a fully-formed string
Returns:
date in form mm/dd/yyyy
- Type
- String
getDateString(days) → {String}
Get the current date as a fully-formed string
Parameters:
Name | Type | Description |
---|---|---|
days |
int | number of days that will have passed (can be negative) |
Returns:
date in form mm/dd/yyyy
- Type
- String
getDayAfterDays(days) → {int}
Get the day after a certain number of days have passed
Parameters:
Name | Type | Description |
---|---|---|
days |
int | number of days that will have passed (can be negative) |
Returns:
day
- Type
- int
getJSON() → {JSONObject|JSONArray}
Get the JSON object or array on the page
Returns:
the JSON info on the page
- Type
- JSONObject | JSONArray
getJSONArray() → {JSONArray}
Get the JSON array on the page
Returns:
the JSON array on the page
- Type
- JSONArray
getJSONObject() → {JSONObject}
Get the JSON object on the page
Returns:
the JSON object on the page
- Type
- JSONObject
getJSONString() → {String}
Get the JSON string on the current page
Returns:
the JSON string
- Type
- String
getMonthAfterDays(days) → {int}
Get the month after a certain number of days have passed
Parameters:
Name | Type | Description |
---|---|---|
days |
int | number of days that will have passed (can be negative) |
Returns:
month
- Type
- int
getProfileValue(name) → {String}
Get a value from the profile
Parameters:
Name | Type | Description |
---|---|---|
name |
String | the name of the profile variable |
Returns:
the value
- Type
- String
getQuery() → {Map.<String, String>}
Get the current URL of the page
Returns:
map of query parameters
- Type
- Map.<String, String>
getSource() → {String}
Get the source of the page
Returns:
the source of the current page
- Type
- String
getText(item) → {String}
Get the text in an element
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector |
Returns:
the contents of the element as text
- Type
- String
getTitle() → {String}
Get the title of the current window
Returns:
the title of the window
- Type
- String
getURL() → {String}
Get the current URL of the page
Returns:
the source of the current page
- Type
- String
getYearAfterDays(days) → {int}
Get the year after a certain number of days have passed
Parameters:
Name | Type | Description |
---|---|---|
days |
int | number of days that will have passed (can be negative) |
Returns:
year
- Type
- int
handleHarvardKey(name)
Handle a HarvardKey login page for a user
Parameters:
Name | Type | Description |
---|---|---|
name |
String | the name of the variable containing the credentials for the user |
isSafari() → {boolean}
Check if the currently-opened window is a Safari browser window
Returns:
true if the browser is Safari
- Type
- boolean
launchAs(name, courseIdopt, appNameopt)
Log into Canvas and launch an LTI app as a specific user from the profile variables.
The value should be a JSON string with the following properties: { [accessToken], [username], [password], [isXID] }
If the accessToken is excluded, we will attempt to launch using the username.
If logging in with a username and the password is excluded, the test runner is prompted to run a password.
If isXID is true, the user will be logged in using the XID login panel.
If both accessToken and username are excluded, the test runner will be prompted to enter an accessToken.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String | the name of the variable containing the credentials for the user | ||
courseId |
int |
<optional> |
courseId from profile
|
the Canvas ID of the course to launch from |
appName |
String |
<optional> |
appName from profile
|
the name of the app as it appears in the course's left-hand nav |
listSelectLabels(selector) → {Array.<String>}
Get the list of labels in a select
Parameters:
Name | Type | Description |
---|---|---|
selector |
String | the css selector for the select element |
Returns:
list of labels
- Type
- Array.<String>
locationToURL(location) → {String}
Turn a location into a URL
Parameters:
Name | Type | Description |
---|---|---|
location |
String | the location to translate (may be a path or a full URL) |
Returns:
URL
- Type
- String
log(message)
Log a message to the console
Parameters:
Name | Type | Description |
---|---|---|
message |
Object | the message to log |
openAnchorInSameTab(item)
Open an anchor link in the same tab
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector of interest |
padWithZeros(number, digits) → {String}
Pad a number with zeros
Parameters:
Name | Type | Description |
---|---|---|
number |
int | the number to pad |
digits |
int | number of digits to require (must be at least this long |
Returns:
padded number
- Type
- String
parentOf(item) → {TestObject}
Get the parent of an element
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector |
Returns:
parent element
- Type
- TestObject
pause()
Pause until the user clicks okay
prompt(label, title) → {String}
Get text from a test runner user. Throws an error if the text is empty
Parameters:
Name | Type | Description |
---|---|---|
label |
String | the label to put in front of the text field |
title |
String | the title of the prompt window |
Returns:
the trimmed text that the user entered
- Type
- String
promptPassword(label, title) → {String}
Get a password from a test runner user. Throws an error if the text is
empty
Parameters:
Name | Type | Description |
---|---|---|
label |
String | the label to put in front of the text field |
title |
String | the title of the prompt window |
Returns:
the trimmed text that the user entered
- Type
- String
refresh()
Refresh the page
runScript(script) → {Object}
Run a script on the page
Parameters:
Name | Type | Description |
---|---|---|
script |
String | the script to run in an anonymous function on the page. If multiple script arguments are included, each argument will be considered a new line of the script. |
Returns:
return value
- Type
- Object
scrollTo(item)
Scroll the page to the element
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector of interest |
sendGETRequest(location) → {JSONArray|JSONObject}
Send a GET request
Parameters:
Name | Type | Description |
---|---|---|
location |
String | path or URL to visit |
Returns:
response
- Type
- JSONArray | JSONObject
setDefaultHost(host)
Set the default host
Parameters:
Name | Type | Description |
---|---|---|
host |
String | name |
setDontUseHTTPS(dontUseHTTPS)
Set whether or not to use HTTPS by default
Parameters:
Name | Type | Description |
---|---|---|
dontUseHTTPS |
boolean | true if not using HTTPS by default |
startControllingIFrame(item)
Start controlling an iframe
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector of the iframe |
stopControllingIFrame()
Stop controlling an iframe and return to the main page
typeInto(item, text, pressEnter)
Type text into an element. This function first removes the previous text in the element
Parameters:
Name | Type | Description |
---|---|---|
item |
TestObject | String | the TestObject or CSS selector of interest |
text |
String | the text to type |
pressEnter |
boolean | if true, after typing into the text field, simulate pressing enter |
uniquify(name) → {String}
Add a unique tag to an object name. Tag may add up to 20 chars.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | the name of the item |
Returns:
the new name of the item with the unique tag
- Type
- String
uniquifySimple(name) → {String}
Add a simple unique tag to an object name, where the simple tag is just
numbers. Tag will be at most 16 chars
Parameters:
Name | Type | Description |
---|---|---|
name |
String | the name of the item |
Returns:
the new name of the item with the unique tag
- Type
- String
visit(location)
Visit a location in the browser
Parameters:
Name | Type | Description |
---|---|---|
location |
String | path or URL to visit |
visitCanvasDELETEEndpoint(path, accessToken, payload) → {JSONArray|JSONObject}
Send a DELETE request to a Canvas API endpoint
Parameters:
Name | Type | Description |
---|---|---|
|
Map | |
path |
String | the path of the API, excluding https://canvas.harvard.edu, example: "/api/v1/users" |
accessToken |
String | a Canvas access token |
payload |
String | the body of the post request |
Returns:
Canvas response
- Type
- JSONArray | JSONObject
visitCanvasGETEndpoint(path, accessToken) → {JSONArray|JSONObject}
Get the value of a Canvas GET API endpoint. Automatically adds a per_page=200 param
Parameters:
Name | Type | Description |
---|---|---|
path |
String | the path of the API, excluding https://canvas.harvard.edu/api/v1, example: "/users" |
accessToken |
String | a Canvas access token |
Returns:
Canvas response
- Type
- JSONArray | JSONObject
visitCanvasPOSTEndpoint(path, accessToken, payload) → {JSONArray|JSONObject}
Send a POST request to a Canvas API endpoint
Parameters:
Name | Type | Description |
---|---|---|
|
Map | |
path |
String | the path of the API, excluding https://canvas.harvard.edu, example: "/api/v1/users" |
accessToken |
String | a Canvas access token |
payload |
String | the body of the post request |
Returns:
Canvas response
- Type
- JSONArray | JSONObject
waitFor(ms)
Wait for a specific number of milliseconds
Parameters:
Name | Type | Description |
---|---|---|
ms |
int | the number of ms to wait |
waitForAtLeastOneElementPresent(items, timeoutSecopt) → {Object}
Wait for any element in a list to be present (check every tenth of a
second for status)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
items |
ArrayList.<(Object|String)> | list of TestObject or CSS selectors of interest | ||
timeoutSec |
int |
<optional> |
10
|
the number of seconds to wait before timing out |
Returns:
the item that was found first, ties broken by which item
shows up in the list first
- Type
- Object
waitForElementAbsent(item, timeoutSecopt)
Wait for an element to not be present (on the page, it does not have to be visible)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
TestObject | String | the TestObject or CSS selector of interest | ||
timeoutSec |
int |
<optional> |
10
|
the number of seconds to wait before timing out |
waitForElementPresent(item, timeoutSecopt)
Wait for an element to be present (on the page, it does not have to be visible)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
TestObject | String | the TestObject or CSS selector of interest | ||
timeoutSec |
int |
<optional> |
10
|
the number of seconds to wait before timing out |
waitForElementVisible(item, timeoutSecopt)
Wait for an element to be visible
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
TestObject | String | the TestObject or CSS selector of interest | ||
timeoutSec |
int |
<optional> |
10
|
the number of seconds to wait before timing out |
waitForElementWithContentsPresent(contents, selector, timeoutSecopt)
Wait for an element with specific contents to be present (on the page, it does not have to be visible)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
contents |
String | the contents to search for | ||
selector |
String | a CSS selector corresponding to the item | ||
timeoutSec |
int |
<optional> |
10
|
the number of seconds to wait before timing out |
waitForElementWithContentsVisible(contents, selector, timeoutSecopt)
Wait for an element with specific contents to be visible
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
contents |
String | the contents to search for | ||
selector |
String | a CSS selector corresponding to the item | ||
timeoutSec |
int |
<optional> |
10
|
the number of seconds to wait before timing out |
waitForFunctionToReturnTrue(testFunction, timeoutSecopt)
Wait until a custom function returns true. Here's how you do it:
Kaixa.waitForFunctionToReturnTrue(x -> {
return [test if wait should end ];
});
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
testFunction |
function | a function that returns true when the wait should finish | ||
timeoutSec |
int |
<optional> |
10
|
the number of seconds to wait before timing out |