{"__v":7,"_id":"56269a8b44c87f0d00fe6378","category":{"__v":12,"_id":"559b65be8b04e90d00702d58","pages":["559b65bf8b04e90d00702d5a","55a46241ffd44e0d00fca056","55a46f45e75ca60d00a39323","55a470b768c7e20d0036d4d6","55a4a758dad9d00d0071fcba","55b6b6276127b12500364560","55baf505d0736b3100bf1033","55c25ef1f2cff20d006d0b8a","56269a8b44c87f0d00fe6378","56498f62f176080d000c78ac","566f59c4fc3abb0d0020fcd5","567cd2228eb5b20d0021059d"],"project":"559b65bd8b04e90d00702d54","version":"559b65bd8b04e90d00702d57","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-07T05:38:06.409Z","from_sync":false,"order":0,"slug":"chimpjs","title":"Chimp.js"},"parentDoc":null,"project":"559b65bd8b04e90d00702d54","user":"559b658d8b04e90d00702d52","version":{"__v":6,"_id":"559b65bd8b04e90d00702d57","project":"559b65bd8b04e90d00702d54","createdAt":"2015-07-07T05:38:05.890Z","releaseDate":"2015-07-07T05:38:05.890Z","categories":["559b65be8b04e90d00702d58","55a46e7468c7e20d0036d4d1","55a4971be6c2470d002a6483","55a4a690e10ba50d00b40bba","55a4bcf31a5f991700a94066","56cf5c8d336aa60b0086a40d"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":["56597d8960571a0d002cd1d3","56a6bde9f857190d00c91302","57fb2964f9c7091700d0d0c9"],"next":{"pages":[],"description":""},"createdAt":"2015-10-20T19:48:27.979Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":10,"body":"The following is a list of examples of how to do common tasks and assertions using:\n* Webdriver.io\n* Synchronous execution\n* Jasmine expectations\n\n*[Click here the full WebdriverIO API](http://webdriver.io/api.html)*\n\nThe variable `browser` is a handle to webdriver. It is shorthand for, or the equivalent of:\n\n`var webdriverio = require('webdriverio');\nvar options = {};\nvar browser=webdriverio.remote(options)`\n\n###### Assert that element exists in dom\n```javascript\nvar doesExist = browser.waitForExist(\"selector\");\n\nexpect(doesExist).toBe(true);\n```\n\n###### Assert that element is not in dom (removed)\nUse `undefined` for second parameter to keep default wait timeout.\n\nThird parameter negates the check.\n\n```javascript\nvar doesNotExist = browser.waitForExist(\"selector\", undefined, true)\n\nexpect(doesNotExist).toBe(true);\n```\n\n###### Assert on number of elements in dom\n```javascript\nbrowser.waitForExist(\"selector\");\nvar elements = browser.elements(\"selector\");\n\nexpect(elements.value.length).toEqual(2);\n// expect(elements.value.length).toBeGreaterThan(2);\n// expect(elements.value.length >= 2).toBe(true);\n```\n\n###### Assert that element has text value\n```javascript\nbrowser.waitForExist(\"selector\");\nvar actualText = browser.getText(\"selector\");\n\nexpect(actualText).toEqual(\"text\");\n```\n\n###### Assert that element has class\n```javascript\nbrowser.waitForExist(\"selector\");\nvar cssClass = browser.getAttribute(\"selector\", \"class\");\n\nexpect(cssClass).toContain(\"my-custom-class\");\n```\n\n###### Click an element\n```javascript\nbrowser.waitForExist(\"selector\");\nbrowser.click(\"selector\");\n```\n\n###### Move to an element\n```javascript\nbrowser.waitForExist(\"selector\");\nbrowser.moveToObject(\"selector\");\n```\n\n###### Drag an element\n```javascript\nbrowser.waitForExist(\"selector\");\nbrowser.moveToObject(\"selector\", 0, 0);\nbrowser.buttonDown();\nbrowser.moveToObject(\"selector\", 50, 5);\nbrowser.buttonUp();\n```\n\n###### Assert on an elements x position\n```javascript\nbrowser.waitForExist(\"selector\");\nvar x = browser.getLocation(\"selector\", \"x\") // Get x or y, if not specified, an object {x, y} is returned.\n\nexpect(x).toEqual(50);\n```\n\n###### Execute custom action (in this case trigger mouseenter on an element\n```javascript\nbrowser.waitForExist(\"selector\");\nbrowser.selectorExecute(\"selector\", function(element) {\n    $(element).trigger(\"mouseenter\");\n});\n```\n\n---\n\n<a href=\"http://quality.xolv.io/?utm_source=XolvOSS&utm_medium=OSSDocs&utm_content=ChimpRM-Footer&utm_campaign=QFLaunch\"><img src=\"https://files.readme.io/764e495-qualityfasterbook-commas.small.png\" width=\"200\" align=\"right\" /></a>\n##Learn the Fundamentals of Testing, Specifications and Become a Chimp Ninja!\n[Checkout our new book](http://quality.xolv.io/?utm_source=XolvOSS&utm_medium=OSSDocs&utm_content=ChimpRM-Footer&utm_campaign=QFLaunch) where you can learn how to can use Chimp across the Full Stack from React to Node.JS, Mocha, Meteor and more.\n\n\n**[Quality, Faster.](http://quality.xolv.io/?utm_source=XolvOSS&utm_medium=OSSDocs&utm_content=ChimpRM-Footer&utm_campaign=QFLaunch)** By Sam Hatoum, creator of Chimp.","excerpt":"Common cases with Chimp","slug":"cheat-sheet","type":"basic","title":"Cheat Sheet"}

Cheat Sheet

Common cases with Chimp

The following is a list of examples of how to do common tasks and assertions using: * Webdriver.io * Synchronous execution * Jasmine expectations *[Click here the full WebdriverIO API](http://webdriver.io/api.html)* The variable `browser` is a handle to webdriver. It is shorthand for, or the equivalent of: `var webdriverio = require('webdriverio'); var options = {}; var browser=webdriverio.remote(options)` ###### Assert that element exists in dom ```javascript var doesExist = browser.waitForExist("selector"); expect(doesExist).toBe(true); ``` ###### Assert that element is not in dom (removed) Use `undefined` for second parameter to keep default wait timeout. Third parameter negates the check. ```javascript var doesNotExist = browser.waitForExist("selector", undefined, true) expect(doesNotExist).toBe(true); ``` ###### Assert on number of elements in dom ```javascript browser.waitForExist("selector"); var elements = browser.elements("selector"); expect(elements.value.length).toEqual(2); // expect(elements.value.length).toBeGreaterThan(2); // expect(elements.value.length >= 2).toBe(true); ``` ###### Assert that element has text value ```javascript browser.waitForExist("selector"); var actualText = browser.getText("selector"); expect(actualText).toEqual("text"); ``` ###### Assert that element has class ```javascript browser.waitForExist("selector"); var cssClass = browser.getAttribute("selector", "class"); expect(cssClass).toContain("my-custom-class"); ``` ###### Click an element ```javascript browser.waitForExist("selector"); browser.click("selector"); ``` ###### Move to an element ```javascript browser.waitForExist("selector"); browser.moveToObject("selector"); ``` ###### Drag an element ```javascript browser.waitForExist("selector"); browser.moveToObject("selector", 0, 0); browser.buttonDown(); browser.moveToObject("selector", 50, 5); browser.buttonUp(); ``` ###### Assert on an elements x position ```javascript browser.waitForExist("selector"); var x = browser.getLocation("selector", "x") // Get x or y, if not specified, an object {x, y} is returned. expect(x).toEqual(50); ``` ###### Execute custom action (in this case trigger mouseenter on an element ```javascript browser.waitForExist("selector"); browser.selectorExecute("selector", function(element) { $(element).trigger("mouseenter"); }); ``` --- <a href="http://quality.xolv.io/?utm_source=XolvOSS&utm_medium=OSSDocs&utm_content=ChimpRM-Footer&utm_campaign=QFLaunch"><img src="https://files.readme.io/764e495-qualityfasterbook-commas.small.png" width="200" align="right" /></a> ##Learn the Fundamentals of Testing, Specifications and Become a Chimp Ninja! [Checkout our new book](http://quality.xolv.io/?utm_source=XolvOSS&utm_medium=OSSDocs&utm_content=ChimpRM-Footer&utm_campaign=QFLaunch) where you can learn how to can use Chimp across the Full Stack from React to Node.JS, Mocha, Meteor and more. **[Quality, Faster.](http://quality.xolv.io/?utm_source=XolvOSS&utm_medium=OSSDocs&utm_content=ChimpRM-Footer&utm_campaign=QFLaunch)** By Sam Hatoum, creator of Chimp.