- Install Nodejs:
- Install mocha:
- npm install -g mocha
- Create test folder:
- Open terminal
- cd Desktop
- mkdir appium-test
- Download test app:
- cd appium-test
- curl -O http://developer.apple.com/library/ios/samplecode/UICatalog/UICatalog.zip
- unzip UICatalog.zip
- cd UICatalog
- xcodebuild -sdk iphonesimulator6.0
- Setup appium:
- Download appium app:
- Run appium server
- Choose "App Path" using UICatalog build .app file:
- UICatalog/build/Release-iphonesimulator/UICatalog.app
- Launch
- Install node modules:
- cd appium-test
- npm install path
- npm install saucelabs
- npm install should
- npm install underscore
- npm install wd
- Create test files:
- driverblock.js
/*global beforeEach:true, afterEach:true, describe:true */ "use strict"; var wd = require('wd') , _ = require("underscore") , sauce = require("saucelabs") , sauceRest = null , path = require("path") , should = require("should") , defaultHost = '127.0.0.1' , defaultPort = 4723 , defaultCaps = { browserName: '' , device: 'iPhone Simulator' , platform: 'Mac' , version: '6.0' //, newCommandTimeout: 60 }; var sauceRest = { username: 'vinhquang09' , password: '1acf93f3-ba7d-4776-a5bc-6958be79b20b' }; var driverBlock = function(tests, host, port, caps, extraCaps) { host = (typeof host === "undefined" || host === null) ? _.clone(defaultHost) : host; port = (typeof port === "undefined" || port === null) ? _.clone(defaultPort) : port; caps = (typeof caps === "undefined" || caps === null) ? _.clone(defaultCaps) : caps; caps = _.extend(caps, typeof extraCaps === "undefined" ? {} : extraCaps); var driverHolder = {driver: null, sessionId: null}; var expectConnError = extraCaps && extraCaps.expectConnError; beforeEach(function(done) { driverHolder.driver = wd.remote(host, port); driverHolder.driver.init(caps, function(err, sessionId) { if (expectConnError && err) { driverHolder.connError = err; return done(); } should.not.exist(err); driverHolder.sessionId = sessionId; driverHolder.driver.setImplicitWaitTimeout(5000, function(err) { should.not.exist(err); done(); }); }); }); afterEach(function(done) { driverHolder.driver.quit(function(err) { if (err && err.status && err.status.code != 6) { throw err; } if (host.indexOf("saucelabs") !== -1 && sauceRest !== null) { sauceRest.updateJob(driverHolder.sessionId, { passed: true }, function() { done(); }); } else { done(); } }); }); tests(driverHolder); }; var describeForApp = function(app, device, appPackage, appActivity) { if (typeof device === "undefined") { device = "ios"; } var browserName, appPath, realDevice; realDevice = "iPhone Simulator"; browserName = "iOS"; appPath = path.resolve(__dirname, app + "/build/Release-iphonesimulator/" + app + ".app"); return function(desc, tests, host, port, caps, extraCaps) { if (typeof extraCaps === "undefined") { extraCaps = {}; } var newExtraCaps = { app: appPath, browserName: browserName, device: realDevice }; driverBlock(tests, host, port, caps, newExtraCaps); }; }; var describeForSauce = function(appUrl) { return function(desc, tests, host, port, extraCaps) { host = typeof host === "undefined" ? 'ondemand.saucelabs.com' : host; port = typeof port === "undefined" ? 80 : port; host = sauceRest.username + ':' + sauceRest.password + '@' + host; var caps = { platform: "Mac 10.8" , name: "First test" , device: "iPhone Simulator" , browserName: "" , app: appUrl , version: "" , tags: ['appium', 'test'] }; driverBlock(tests, host, port, caps, extraCaps); }; }; module.exports.block = driverBlock; module.exports.describeForApp = describeForApp; module.exports.describeForSauce = describeForSauce;
- simple.js:
/*global it:true */ "use strict"; var should = require("should") , describeWd = require("./driverblock.js").describeForApp('UICatalog'); //, describeWd = require("./driverblock.js").describeForSauce('http://developer.apple.com/library/ios/samplecode/UICatalog/UICatalog.zip'); describeWd('moveTo and click', function(h) { it('should be able to click on arbitrary x-y elements', function(done) { h.driver.elementsByTagName('tableCell', function(err, els) { should.not.exist(err); h.driver.moveTo(els[0], 10, 10, function(err) { should.not.exist(err); h.driver.click(function(err) { should.not.exist(err); h.driver.elementByXPath("button[@name='Rounded']", function(err, el) { should.not.exist(err); should.exist(el.value); done(); }); }); }); }); }); });
- Run test:
- mocha -t 60000 -R spec simple.js
Good luck!
Really nice information. continue to share the information
ReplyDeleteBarker and Stonehouse
Oak Furniture Leeds
Pratts Furniture