diff --git a/api/expect.md b/api/expect.md index 75cb5007..0598413e 100644 --- a/api/expect.md +++ b/api/expect.md @@ -1,8 +1,24 @@ ## Expect API -Nightwatch provides a fluent BDD-style interface for performing assertions on elements, defined on the expect namespace on the main Nightwatch instance. It is based on the Chai Expect assertion library and provides a greater level of flexibility, also adding new capabilities over the classic assert interface. +Nightwatch provides a fluent BDD-style interface for performing assertions on values and elements with the expect namespace on the main Nightwatch instance. It is based on the Chai Expect assertion library and provides a greater level of flexibility, also adding new capabilities over the classic assert interface. It uses a chain-able language to construct assertions given a value or element. -It uses a chain-able language to construct assertions given an element specified by a css/xpath selector. A simple example looks like the following: +As you would expect (pun intended) from Chai, you can use it to check text values directly: + +
+
test('delete node from search and ensure it is gone', function(browser) {
+  browser
+    .assert.textContains(`${targetNodeSelector} #nodeContent`, targetNodeContent)
+    .click({ selector: `${targetNodeSelector} #moreOptionsButton`, index: 0 })
+    .click({ selector: `${targetNodeSelector} #nodeDeleteButton`, index: 0 })
+    .click({ selector: `${targetNodeSelector} #confirmNodeDeleteButton`, index: 0 })
+    .findElements(`${targetNodeSelector} #nodeCard #nodeContent`, nodeContents => {
+      nodeContents.value.forEach(item => {
+        browser.elementIdText(item.getId(), text => browser.expect(text.value).to.not.equal(targetNodeContent))
+      })
+    })
+};
+ +But you may also target an element specified by a css/xpath selector. A simple example looks like the following:
this.demoTest = function (browser) {