cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-10399) Implement Appium tests for Contacts plugin
Date Mon, 14 Mar 2016 09:52:33 GMT

    [ https://issues.apache.org/jira/browse/CB-10399?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15193003#comment-15193003
] 

ASF GitHub Bot commented on CB-10399:
-------------------------------------

Github user alsorokin commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-contacts/pull/101#discussion_r55976166
  
    --- Diff: appium-tests/helpers/contactsHelper.js ---
    @@ -0,0 +1,222 @@
    +/* jshint node: true */
    +/*
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + *
    +*/
    +
    +'use strict';
    +
    +function prepare(item) {
    +    if (typeof item === 'object') {
    +        return JSON.stringify(item);
    +    }
    +    if (typeof item === 'string') {
    +        return '"' + item + '"';
    +    }
    +    return undefined;
    +}
    +
    +module.exports.getContactName = function (firstName, lastName) {
    +    return {
    +        formatted: firstName == lastName === undefined ? null : firstName + ' ' + lastName,
    +        familyName: lastName,
    +        givenName: firstName,
    +        middleName: ''
    +    };
    +};
    +
    +module.exports.getAddContactCode = function (displayName, contactName, phoneNumber) {
    +    var preparedDisplayName = prepare(displayName);
    +    console.log('preparedDisplayName is ' + preparedDisplayName);
    +    var preparedContactName = prepare(contactName);
    +    var preparedPhoneNumber = prepare(phoneNumber);
    +
    +    var result =
    +        'try {\n' +
    +        '    var results = document.getElementById("info");\n' +
    +        '    var contact = navigator.contacts.create({ "displayName": ' + preparedDisplayName
+ ', "name": ' + preparedContactName + ', "note": "DeleteMe" });\n' +
    +
    +        '    var phoneNumbers = [1];\n' +
    +        '    phoneNumbers[0] = new ContactField("work", ' + preparedPhoneNumber + ',
true);\n' +
    +        '    contact.phoneNumbers = phoneNumbers;\n' +
    +
    +        '    contact.save(function() {\n' +
    +        '        results.innerHTML = "' + (displayName || 'Nameless contact') + ' saved.";\n'
+
    +        '    }, function(e) {\n' +
    +        '        if (e.code === ContactError.NOT_SUPPORTED_ERROR) {\n' +
    +        '            results.innerHTML = "Saving contacts not supported.";\n' +
    +        '        } else {\n' +
    +        '            results.innerHTML = "Contact save failed: error " + e.code;\n' +
    +        '        }\n' +
    +        '    });\n' +
    +        '} catch (e) {\n' +
    +        '    var results = document.getElementById("info");\n' +
    +        '    results.innerHTML = "ERROR: " + e.code;\n' +
    +        '}\n';
    +
    +    return result;
    +};
    +
    +module.exports.getGetContactsCode = function (filter) {
    +    var preparedFilter = prepare(filter);
    +
    +    var result =
    +        'var results = document.getElementById("info");\n' +
    +        'var obj = new ContactFindOptions();\n' +
    +        'if (' + preparedFilter + ') {\n' +
    +        '    obj.filter = ' + preparedFilter + ';\n' +
    +        '}\n' +
    +        'obj.multiple = true;\n' +
    +        'navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails", "urls",
"note"], function(contacts) {\n' +
    +        '    var s = "";\n' +
    +        '    if (contacts.length === 0) {\n' +
    +        '        s = "No contacts found";\n' +
    +        '    } else {\n' +
    +        '        s = "Number of contacts: " + contacts.length + "<br><table
width=100%><tr><th>Name</th><td>Phone</td><td>Email</td></tr>";\n'
+
    +        '        for (var i = 0; i < contacts.length; i++) {\n' +
    +        '            var contact = contacts[i];\n' +
    +        '            var contactNameTag = contact.name ? "<tr><td>" + contact.name.formatted
+ "</td><td>" : "<tr><td>(No Name)</td><td>";\n' +
    +        '            s = s + contactNameTag;\n' +
    +        '            if (contact.phoneNumbers && contact.phoneNumbers.length
> 0) {\n' +
    +        '                s = s + contact.phoneNumbers[0].value;\n' +
    +        '            }\n' +
    +        '            s = s + "</td><td>";\n' +
    +        '            if (contact.emails && contact.emails.length > 0) {\n'
+
    +        '                s = s + contact.emails[0].value;\n' +
    +        '            }\n' +
    +        '            s = s + "</td></tr>";\n' +
    +        '    }\n' +
    +        '        s = s + "</table>";\n' +
    +        '    }\n' +
    +        '    results.innerHTML = s;\n' +
    +        '}, function(e) {\n' +
    +        '   results.innerHTML = "Search failed: error " + e.code;\n' +
    +        '}, obj);';
    +
    +    return result;
    +};
    +
    +module.exports.getPickContactCode = function () {
    +    var result =
    +        'var results = document.getElementById("info");\n' +
    +        'navigator.contacts.pickContact(\n' +
    +        '    function (contact) {\n' +
    +        '        results.innerHTML = contact ?\n' +
    +        '            "Picked contact: <pre>" + JSON.stringify(contact, null, 4)
+ "</pre>" :\n' +
    +        '            "No contacts found";\n' +
    +        '    },\n' +
    +        '    function (e) {\n' +
    +        '        results.innerHTML = e && e.code === ContactError.OPERATION_CANCELLED_ERROR
?\n' +
    +        '                "Pick cancelled" :\n' +
    +        '                "Pick failed: " + (e && e.code);\n' +
    +        '    }\n' +
    +        ');';
    +
    +    return result;
    +};
    +
    +module.exports.getRenameContactCode = function (oldDisplayName, newDisplayName, newName)
{
    +    // these default values are copied from manual contacts tests
    +    if (!oldDisplayName) {
    +        oldDisplayName = 'Dooney Evans';
    +    }
    +    if (!newDisplayName) {
    +        newDisplayName = 'Urist McContact';
    +    }
    +    if (!newName) {
    +        newName = module.exports.getContactName('Urist', 'McContact');
    +    }
    +    var preparedOldDisplayName = prepare(oldDisplayName);
    +    var preparedNewDisplayName = prepare(newDisplayName);
    +    var preparedNewName = prepare(newName);
    +
    +    var result =
    +        'var results = document.getElementById("info");\n' +
    +        'var obj = new ContactFindOptions();\n' +
    +        'obj.filter = ' + preparedOldDisplayName + ';\n' +
    +        'obj.multiple = false;\n' +
    +
    +        'navigator.contacts.find(["displayName", "name"], function(contacts) {\n' +
    +        '    if (contacts.length === 0) {\n' +
    +        '        results.innerHTML = "No contacts to update.";\n' +
    +        '        return;\n' +
    +        '    }\n' +
    +        '    var contact = contacts[0];\n' +
    +        '    contact.displayName = ' + preparedNewDisplayName + ';\n' +
    +        '    contact.name = ' + preparedNewName + ';\n' +
    +        '    contact.save(function(updated) {\n' +
    +        '        results.innerHTML = "Contact updated.";\n' +
    +        '    },function(e) {\n' +
    +        '        results.innerHTML = "Update failed: error " + e.code;\n' +
    +        '    });\n' +
    +        '}, function(e) {\n' +
    +        '    results.innerHTML = "Search failed: error " + e.code;\n' +
    +        '}, obj);';
    +
    +    return result;
    +};
    +
    +module.exports.getRemoveTestContactsCode = function () {
    +    var result =
    +        'var results = document.getElementById("info");\n' +
    +        'results.innerHTML = "";\n' +
    +        'var obj = new ContactFindOptions();\n' +
    +        'obj.filter = "DeleteMe";\n' +
    +        'obj.multiple = true;\n' +
    +        'navigator.contacts.find(["note"], function(contacts) {\n' +
    +        '    var removes = [];\n' +
    +        '    contacts.forEach(function(contact) {\n' +
    +        '        removes.push(contact);\n' +
    +        '    });\n' +
    +        '    if (removes.length === 0) {\n' +
    +        '        results.innerHTML = "No contacts to remove";\n' +
    +        '        return;\n' +
    +        '    }\n' +
    +
    +        '   var nextToRemove;\n' +
    +        '   if (removes.length > 0) {\n' +
    +        '        nextToRemove = removes.shift();\n' +
    +        '    }\n' +
    +
    +        '    function removeNext(item) {\n' +
    +        '        if (typeof item === "undefined") {\n' +
    +        '            return;\n' +
    +        '        }\n' +
    +
    +        '        if (removes.length > 0) {\n' +
    +        '            nextToRemove = removes.shift();\n' +
    +        '        } else {\n' +
    +        '            nextToRemove = undefined;\n' +
    +        '        }\n' +
    +
    +        '        item.remove(function removeSucceeded() {\n' +
    +        '            results.innerHTML += "Removed a contact with ID " + item.id + "<br/>";\n'
+
    +        '            removeNext(nextToRemove);\n' +
    +        '        }, function removeFailed() {\n' +
    +        '            results.innerHTML += "Failed to remove a contact with ID " + item.id
+ "<br/>";\n' +
    +        '            removeNext(nextToRemove);\n' +
    +        '        });\n' +
    +        '    }\n' +
    +        '    removeNext(nextToRemove);\n' +
    +        '}, function(e) {\n' +
    +        '   results.innerHTML = "Search failed: error " + e.code;\n' +
    +        '}, obj);';
    +
    +    return result;
    +};
    --- End diff --
    
    There are other way: we could just click the buttons in the mobilespec app's manual tests.
    I've found a couple of downsides of such approach:
    - We are tightly tied to the mobilespec app and its implementation: should there be changes
to it's markup/navigation, or to the manual tests, we're bound to change the appium tests
too
    - Appium tests look more complicated. For example, to debug a failing Appium test which
clicks a button in the manual test I need to look at the Appium code, see which button is
clicked, like here: `elementByXPath('//a[text()="Add new nameless contact"]')`, go to the
manual tests, find the code that creates this particular button and finally find a click handler
function for this particular button. All this opposed to just having the executed code close
at hand, in the helper function.
    - Clicking buttons can be difficult :) For example, Appium is having a huge problem scrolling
the page to find a button which is out of view on iOS simulator.
    
    Could you please describe your thoughts about the current implementation and why are you
against it?


> Implement Appium tests for Contacts plugin
> ------------------------------------------
>
>                 Key: CB-10399
>                 URL: https://issues.apache.org/jira/browse/CB-10399
>             Project: Apache Cordova
>          Issue Type: Task
>          Components: Medic, Plugin Contacts
>            Reporter: Alexander Sorokin
>            Assignee: Alexander Sorokin
>




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message