Kaixa

Author:
  • Gabe Abrams
Kaixa commands

Methods

(static) launchLTIUsingToken(accessToken, courseIdopt, appNameopt)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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()

Author:
  • Gabe Abrams
Close the current window/tab

convertToTestObject(obj) → {TestObject}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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()

Author:
  • Gabe Abrams
Close the browser

elementAbsent(item) → {boolean}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
Exit with an error
Parameters:
Name Type Description
message String a human-readable message to display

extractDataFromClass(item, classPrefix) → {String}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Rute Santos
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}

Author:
  • Gabe Abrams
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
Name Type Attributes Default Description
startSelector String css selector for the start element
startContents String <optional>
text contents to use to narrow the search for the start element. NOTE: must be the contents of the element, not contents of a child element!
ancestor String <optional>
parent the ancestor to traverse up to. Allowed options: "parent" or "grandparent" or "greatgrandparent" or "greatgreatgrandparent"
ancestorLevel int <optional>
1 alternative method for identifying the ancestor (1 = parent, 2 = grandparent, 3 = greatgrandparent, ...)
childSelector String css selector for the child element
childContents String <optional>
text contents to use to narrow the search for the child element. NOTE: must be the contents of the element, not contents of a child element!
Returns:
element
Type
TestObject

getAttribute(item, attribute) → {String}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
Get the current day
Returns:
day
Type
int

getCurrentMonth() → {int}

Author:
  • Gabe Abrams
Get the current month
Returns:
month
Type
int

getCurrentYear() → {int}

Author:
  • Gabe Abrams
Get the current year
Returns:
year
Type
int

getDateString() → {String}

Author:
  • Gabe Abrams
Get the current date as a fully-formed string
Returns:
date in form mm/dd/yyyy
Type
String

getDateString(days) → {String}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
Get the JSON object or array on the page
Returns:
the JSON info on the page
Type
JSONObject | JSONArray

getJSONArray() → {JSONArray}

Author:
  • Gabe Abrams
Get the JSON array on the page
Returns:
the JSON array on the page
Type
JSONArray

getJSONObject() → {JSONObject}

Author:
  • Gabe Abrams
Get the JSON object on the page
Returns:
the JSON object on the page
Type
JSONObject

getJSONString() → {String}

Author:
  • Gabe Abrams
Get the JSON string on the current page
Returns:
the JSON string
Type
String

getMonthAfterDays(days) → {int}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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>}

Author:
  • Gabe Abrams
Get the current URL of the page
Returns:
map of query parameters
Type
Map.<String, String>

getSource() → {String}

Author:
  • Gabe Abrams
Get the source of the page
Returns:
the source of the current page
Type
String

getText(item) → {String}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
Get the title of the current window
Returns:
the title of the window
Type
String

getURL() → {String}

Author:
  • Gabe Abrams
Get the current URL of the page
Returns:
the source of the current page
Type
String

getYearAfterDays(days) → {int}

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
Check if the currently-opened window is a Safari browser window
Returns:
true if the browser is Safari
Type
boolean

launchAs(name, courseIdopt, appNameopt)

Author:
  • Gabe Abrams
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>}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
Log a message to the console
Parameters:
Name Type Description
message Object the message to log

openAnchorInSameTab(item)

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
Get the parent of an element
Parameters:
Name Type Description
item TestObject | String the TestObject or CSS selector
Returns:
parent element
Type
TestObject

pause()

Author:
  • Gabe Abrams
Pause until the user clicks okay

prompt(label, title) → {String}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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()

Author:
  • Gabe Abrams
Refresh the page

runScript(script) → {Object}

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
Scroll the page to the element
Parameters:
Name Type Description
item TestObject | String the TestObject or CSS selector of interest

sendGETRequest(location) → {JSONArray|JSONObject}

Author:
  • Gabe Abrams
Send a GET request
Parameters:
Name Type Description
location String path or URL to visit
Returns:
response
Type
JSONArray | JSONObject

setDefaultHost(host)

Author:
  • Gabe Abrams
Set the default host
Parameters:
Name Type Description
host String name

setDontUseHTTPS(dontUseHTTPS)

Author:
  • Gabe Abrams
Set whether or not to use HTTPS by default
Parameters:
Name Type Description
dontUseHTTPS boolean true if not using HTTPS by default

startControllingIFrame(item)

Author:
  • Gabe Abrams
Start controlling an iframe
Parameters:
Name Type Description
item TestObject | String the TestObject or CSS selector of the iframe

stopControllingIFrame()

Author:
  • Gabe Abrams
Stop controlling an iframe and return to the main page

typeInto(item, text, pressEnter)

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
Visit a location in the browser
Parameters:
Name Type Description
location String path or URL to visit

visitCanvasDELETEEndpoint(path, accessToken, payload) → {JSONArray|JSONObject}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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}

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
Wait for a specific number of milliseconds
Parameters:
Name Type Description
ms int the number of ms to wait

waitForAtLeastOneElementPresent(items, timeoutSecopt) → {Object}

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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)

Author:
  • Gabe Abrams
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