2014-09-30 66 views
2

我们有一个使用sproutcore开发的丰富的UI应用程序。我们试图在Ruby中使用Selenium webdriver自动化页面。使用动态生成的ID和隐藏项目,我们发现很难识别某些元素。应用程序很复杂。开发人员表示他们无法为隐藏的项目或框架添加唯一的图层ID。对于静态页面,他们添加了唯一的图层标识或类名称。QA Automation for rich sproutcore应用程序

我想从我的朋友那里了解他们用于sproutcore应用程序的自动化功能吗? 他们如何解决这些问题?

任何指针表示赞赏。

回答

0

即使网络元素

动态生成的ID和隐藏的项目,我们发现很难确定一些

一种解决方案是要问,如果开发人员可以添加对他们命名模式,所以刚刚生成的最后一个字符即时。通过这样做,你可以使用其中的某些位置的方法:

0

的一种方法,将与SproutCore的工作是使用SproutCore的视图树来标识元素而不是按层ID或类。例如,考虑这个基本的主网页,

MyApp.mainPage = SC.Page.create({ 

    mainPane: SC.MainPane.extend({ 

    childViews: ['header', 'mainContent', 'footer'], 

    header: SC.ToolbarView.extend({ 
     layout: { height: 44 }, 

     childViews: ['headerButton'], 

     headerButton: SC.ButtonView.extend({ 
     layout: { centerX: 0, centerY: 0, height: 40, width: 100 }, 
     title: "Click Here" 
     }) 

    }), 

    mainContent: SC.View.extend({ 
     layout: { top: 44, bottom: 33 }, 

    // etc. 

虽然我们不知道这些元件的层IDS事前,我们知道在JavaScript中的父子关系。举例来说,如果我需要某些元素从页面,我可能会抓住他们提前像这样,

// Retrieve target views for the current page. 
var mainPane = MyApp.mainPage.get('mainPane'), 
    header = mainPane.get('header'), 
    headerButton = header.get('headerButton'), 
    // … etc. 

// Then retrieve an element for acting upon. 
var buttonLayer = headerButton.get('layer'); // returns a DOM node 

// Or retrieve an element id for acting upon. 
var buttonLayerId = headerButton.get('layerId'); // returns the auto-generated id 

虽然我没有与硒的第一手经验,看来,你可以使用execute_script的webdriver实例方法运行一些简单的查找,返回您需要的元素或您需要的元素的ID。

最后,请记住,一些意见可能会有动态变化的儿童,特别是SC.CollectionView子类如SC.ListView。在这种情况下,一旦您定位到父视图,您就可以使用特定于该父视图的方法轻松访问您需要的子项,例如itemViewForContentIndex(idx)以获取列表的项目视图。

0

我用硒来自动(通过詹金斯)一些 QA测试为Sproutcore app,在我的经验,这通常是足够具体的类名添加到SproutCore的对象,然后使用XPath表达式中硒针对那些类。

实施例:

bottomRightView: SC.View.design({ 
     classNames: ["bottomRightView"], 
     layout: { top: 60, width: 299, bottom:50, right: 15, zIndex: Maps.RIGHT_TOOL_BOX_PANE_ZINDEX }, 
     childViews: "resultsView noResultsView buttons featureView".w(), 

XPath表达式:

xpath=//div[contains(@class,'bottomRightView')] 

它始终是可能使用// @如果(调试)语句排除那些类名从生产的基础之上。

上面提到的应用程序的Selenium IDE脚本示例:https://github.com/unicolet/mappu/tree/master/tests/selenium