mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-03-16 22:11:02 +08:00
CB-10619 Appium tests: Properly switch to webview
This commit is contained in:
parent
a060fb36f3
commit
61b77951e1
@ -16,8 +16,15 @@ var cameraHelper = require('../helpers/cameraHelper');
|
|||||||
describe('Camera tests Android.', function () {
|
describe('Camera tests Android.', function () {
|
||||||
var driver,
|
var driver,
|
||||||
startingMessage = 'Ready for action!',
|
startingMessage = 'Ready for action!',
|
||||||
isTestPictureSaved = false, // this indicates if device library has test picture
|
// the name of webview context, it will be changed to match needed context if there are named ones:
|
||||||
stopFlag = false; // this indecates that there was critical error and tests cannot go on
|
webviewContext = 'WEBVIEW',
|
||||||
|
// this indicates if device library has test picture:
|
||||||
|
isTestPictureSaved = false,
|
||||||
|
// this indecates that there was critical error and tests cannot continue:
|
||||||
|
stopFlag = false,
|
||||||
|
// we need to know the screen width and height to properly click on the first image in the gallery
|
||||||
|
screenWidth = 360,
|
||||||
|
screenHeight = 567;
|
||||||
|
|
||||||
function win() {
|
function win() {
|
||||||
expect(true).toBe(true);
|
expect(true).toBe(true);
|
||||||
@ -65,7 +72,7 @@ describe('Camera tests Android.', function () {
|
|||||||
var command = "navigator.camera.getPicture(function (result) { document.getElementById('info').innerHTML = result.slice(0, 100); }, " +
|
var command = "navigator.camera.getPicture(function (result) { document.getElementById('info').innerHTML = result.slice(0, 100); }, " +
|
||||||
"function (err) { document.getElementById('info').innerHTML = 'ERROR: ' + err; }," + JSON.stringify(options) + ");";
|
"function (err) { document.getElementById('info').innerHTML = 'ERROR: ' + err; }," + JSON.stringify(options) + ");";
|
||||||
return driver
|
return driver
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
.execute(command)
|
.execute(command)
|
||||||
.sleep(5000)
|
.sleep(5000)
|
||||||
.context('NATIVE_APP')
|
.context('NATIVE_APP')
|
||||||
@ -78,11 +85,14 @@ describe('Camera tests Android.', function () {
|
|||||||
options.sourceType === cameraConstants.PictureSourceType.SAVEDPHOTOALBUM)) {
|
options.sourceType === cameraConstants.PictureSourceType.SAVEDPHOTOALBUM)) {
|
||||||
var touchTile = new wd.TouchAction(),
|
var touchTile = new wd.TouchAction(),
|
||||||
swipeRight = new wd.TouchAction();
|
swipeRight = new wd.TouchAction();
|
||||||
touchTile.press({x: 50, y: 50}).release();
|
touchTile.press({x: Math.round(screenWidth / 4), y: Math.round(screenHeight / 5)}).release();
|
||||||
swipeRight.press({x: 3, y: 100}).moveTo({x: 100, y: 100}).release();
|
swipeRight.press({x: 10, y: Math.round(screenHeight / 2)})
|
||||||
|
.wait(300)
|
||||||
|
.moveTo({x: Math.round(screenWidth / 2), y: Math.round(screenHeight / 2)})
|
||||||
|
.release();
|
||||||
return driver
|
return driver
|
||||||
.performTouchAction(swipeRight)
|
.performTouchAction(swipeRight)
|
||||||
.sleep(1000)
|
.sleep(3000)
|
||||||
.elementByXPath('//*[@text="Gallery"]')
|
.elementByXPath('//*[@text="Gallery"]')
|
||||||
.then(function (element) {
|
.then(function (element) {
|
||||||
return element.click().sleep(5000);
|
return element.click().sleep(5000);
|
||||||
@ -118,14 +128,20 @@ describe('Camera tests Android.', function () {
|
|||||||
function enterTest() {
|
function enterTest() {
|
||||||
if (stopFlag) {
|
if (stopFlag) {
|
||||||
return driver
|
return driver
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
throw 'stopFlag is on!';
|
throw 'stopFlag is on!';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return driver
|
return driver
|
||||||
// trying to determine where we are
|
// trying to determine where we are
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
|
.then(function (result) {
|
||||||
|
console.log(result);
|
||||||
|
})
|
||||||
|
.fail(function (error) {
|
||||||
|
expect(true).toFailWithMessage(error);
|
||||||
|
})
|
||||||
.elementById('info')
|
.elementById('info')
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return driver; //we're already on the test screen
|
return driver; //we're already on the test screen
|
||||||
@ -155,7 +171,7 @@ describe('Camera tests Android.', function () {
|
|||||||
|
|
||||||
function checkPicture(shouldLoad) {
|
function checkPicture(shouldLoad) {
|
||||||
return driver
|
return driver
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
.elementById('info')
|
.elementById('info')
|
||||||
.getAttribute('innerHTML')
|
.getAttribute('innerHTML')
|
||||||
.then(function (html) {
|
.then(function (html) {
|
||||||
@ -188,7 +204,7 @@ describe('Camera tests Android.', function () {
|
|||||||
|
|
||||||
function deleteImage() {
|
function deleteImage() {
|
||||||
var holdTile = new wd.TouchAction();
|
var holdTile = new wd.TouchAction();
|
||||||
holdTile.press({x: 50, y: 50}).wait(1000).release();
|
holdTile.press({x: Math.round(screenWidth / 3), y: Math.round(screenHeight / 5)}).wait(1000).release();
|
||||||
return driver
|
return driver
|
||||||
.performTouchAction(holdTile)
|
.performTouchAction(holdTile)
|
||||||
.elementByXPath('//android.widget.TextView[@text="Delete"]')
|
.elementByXPath('//android.widget.TextView[@text="Delete"]')
|
||||||
@ -229,17 +245,63 @@ describe('Camera tests Android.', function () {
|
|||||||
.sleep(10000)
|
.sleep(10000)
|
||||||
.finally(done);
|
.finally(done);
|
||||||
});
|
});
|
||||||
}, 240000);
|
}, 320000);
|
||||||
|
|
||||||
|
it('camera.ui.util determine webview context name', function (done) {
|
||||||
|
var i = 0;
|
||||||
|
return driver
|
||||||
|
.contexts(function (err, contexts) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
for (i = 0; i < contexts.length; i++) {
|
||||||
|
if (contexts[i].indexOf('mobilespec') >= 0) {
|
||||||
|
webviewContext = contexts[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
|
it('camera.ui.util determine screen dimensions', function (done) {
|
||||||
|
return enterTest()
|
||||||
|
.execute('document.getElementById(\'info\').innerHTML = window.innerWidth;')
|
||||||
|
.sleep(5000)
|
||||||
|
.elementById('info')
|
||||||
|
.getAttribute('innerHTML')
|
||||||
|
.then(function (html) {
|
||||||
|
if (html !== startingMessage) {
|
||||||
|
screenWidth = Number(html);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.execute('document.getElementById(\'info\').innerHTML = \'' + startingMessage + '\';')
|
||||||
|
.execute('document.getElementById(\'info\').innerHTML = window.innerHeight;')
|
||||||
|
.sleep(5000)
|
||||||
|
.elementById('info')
|
||||||
|
.getAttribute('innerHTML')
|
||||||
|
.then(function (html) {
|
||||||
|
if (html !== startingMessage) {
|
||||||
|
screenHeight = Number(html);
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}, 60000);
|
||||||
|
|
||||||
describe('Specs.', function () {
|
describe('Specs.', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
if (!stopFlag) {
|
if (!stopFlag) {
|
||||||
return driver
|
return driver
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
|
.then(function () {
|
||||||
|
return driver; // no-op
|
||||||
|
}, function (error) {
|
||||||
|
expect(true).toFailWithMessage(error);
|
||||||
|
})
|
||||||
.execute('document.getElementById("info").innerHTML = "' + startingMessage + '";')
|
.execute('document.getElementById("info").innerHTML = "' + startingMessage + '";')
|
||||||
.finally(done);
|
.finally(done);
|
||||||
}
|
}
|
||||||
}, 20000);
|
done();
|
||||||
|
}, 600000);
|
||||||
|
|
||||||
// getPicture() with saveToPhotoLibrary = true
|
// getPicture() with saveToPhotoLibrary = true
|
||||||
it('camera.ui.spec.1 Saving the picture to photo library', function (done) {
|
it('camera.ui.spec.1 Saving the picture to photo library', function (done) {
|
||||||
@ -250,7 +312,7 @@ describe('Camera tests Android.', function () {
|
|||||||
saveToPhotoAlbum: true
|
saveToPhotoAlbum: true
|
||||||
};
|
};
|
||||||
enterTest()
|
enterTest()
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return getPicture(options);
|
return getPicture(options);
|
||||||
})
|
})
|
||||||
@ -276,7 +338,7 @@ describe('Camera tests Android.', function () {
|
|||||||
return getPicture(options, true);
|
return getPicture(options, true);
|
||||||
})
|
})
|
||||||
.sleep(5000)
|
.sleep(5000)
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
.elementById('info')
|
.elementById('info')
|
||||||
.getAttribute('innerHTML')
|
.getAttribute('innerHTML')
|
||||||
.then(function (html) {
|
.then(function (html) {
|
||||||
@ -336,7 +398,7 @@ describe('Camera tests Android.', function () {
|
|||||||
sourceType: cameraConstants.PictureSourceType.CAMERA,
|
sourceType: cameraConstants.PictureSourceType.CAMERA,
|
||||||
destinationType: cameraConstants.DestinationType.FILE_URI };
|
destinationType: cameraConstants.DestinationType.FILE_URI };
|
||||||
enterTest()
|
enterTest()
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return getPicture(options, true);
|
return getPicture(options, true);
|
||||||
})
|
})
|
||||||
@ -344,7 +406,7 @@ describe('Camera tests Android.', function () {
|
|||||||
.context("NATIVE_APP")
|
.context("NATIVE_APP")
|
||||||
.elementByXPath('//android.widget.ImageView[contains(@resource-id,\'cancel\')]')
|
.elementByXPath('//android.widget.ImageView[contains(@resource-id,\'cancel\')]')
|
||||||
.click()
|
.click()
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return driver
|
return driver
|
||||||
.elementByXPath('//*[contains(text(),"Camera cancelled")]')
|
.elementByXPath('//*[contains(text(),"Camera cancelled")]')
|
||||||
@ -371,7 +433,7 @@ describe('Camera tests Android.', function () {
|
|||||||
sourceType: cameraConstants.PictureSourceType.CAMERA,
|
sourceType: cameraConstants.PictureSourceType.CAMERA,
|
||||||
destinationType: cameraConstants.DestinationType.FILE_URI };
|
destinationType: cameraConstants.DestinationType.FILE_URI };
|
||||||
enterTest()
|
enterTest()
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return getPicture(options, true);
|
return getPicture(options, true);
|
||||||
})
|
})
|
||||||
@ -384,7 +446,7 @@ describe('Camera tests Android.', function () {
|
|||||||
.elementByXPath('//*[contains(@resource-id,\'discard\')]')
|
.elementByXPath('//*[contains(@resource-id,\'discard\')]')
|
||||||
.click()
|
.click()
|
||||||
.sleep(5000)
|
.sleep(5000)
|
||||||
.context('WEBVIEW')
|
.context(webviewContext)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return driver
|
return driver
|
||||||
.elementByXPath('//*[contains(text(),"Camera cancelled")]')
|
.elementByXPath('//*[contains(text(),"Camera cancelled")]')
|
||||||
|
@ -16,9 +16,12 @@ module.exports.getDriver = function (platform, callback) {
|
|||||||
platformVersion: global.PLATFORM_VERSION || '',
|
platformVersion: global.PLATFORM_VERSION || '',
|
||||||
deviceName: global.DEVICE_NAME || '',
|
deviceName: global.DEVICE_NAME || '',
|
||||||
app: global.PACKAGE_PATH,
|
app: global.PACKAGE_PATH,
|
||||||
autoAcceptAlerts: true
|
autoAcceptAlerts: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (process.env.CHROMEDRIVER_EXECUTABLE) {
|
||||||
|
driverConfig.chromedriverExecutable = process.env.CHROMEDRIVER_EXECUTABLE;
|
||||||
|
}
|
||||||
driver = wd.promiseChainRemote(serverConfig);
|
driver = wd.promiseChainRemote(serverConfig);
|
||||||
module.exports.configureLogging(driver);
|
module.exports.configureLogging(driver);
|
||||||
driver.init(driverConfig).setImplicitWaitTimeout(10000)
|
driver.init(driverConfig).setImplicitWaitTimeout(10000)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user