More Appium testing

I wanted to include one more test (not used in this application) that I have written in the past for a different project since this will give you an idea of just how powerful Appium can be:

it("should type in an element", function (done) {
driver
.elementByXPath('//' + nsAppium.getXPathElement("EditText") + "[@text='Enter your name']")
.sendKeys('Testing')
.text()
.then(function (v) {
if ('Testing' !== v) {
done(new Error("Value in name field does not match"));
} else {
done();
}
}, done);
});
});

The first thing you might note is that I did not return the promise chain. That is because this example shows how to use the asynchronous support of it. For an async support, you can use a promise or make the function coming into it have a done callback function. When Mocha detects a callback function in the it, it will run your it tests in the async mode and doesn't need the promise to let it know that it can resume with the next test. Sometimes, you may just want to maintain full control or you may be calling code that requires async callbacks.

This test looks for a EditText element that contains Enter your name. Then, it actually types Testing into it using the sendKeys. Next, it asks for the text out of the field and uses the then part of the promise to check the value against the hardcoded testing. When it is all finished, it calls the done function. If you pass the done function an Error object, then it knows that the test failed. So, you can see in the if statement that we passed a new Error and that we put the done function in the catch part of the then statement.

We have barely scratched the surface of what you can do with Appium, Should, Mocha, and Chia. You can control pretty much all aspects of the application as if you were manually doing each step. Initially, in your development, manually testing is a lot faster. However, as you start to build up end-to-end tests, each time you make changes, you can check whether the app still works properly, and you do not have to sit in front of multiple devices for any amount of time--you just start the tests and see the results later.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.10.169