StanwoodUITesting 0.5

StanwoodUITesting 0.5

Tal Zion 维护。



  • stanwood

StanwoodUITesting 框架

Swift Version iOS 8+ Build Status

目录

作者

Tal Zion [email protected]

安装

target 'Project_Tests' do
      inherit! :search_paths
      pod 'StanwoodUITesting'
end

用法

iOS 开发者用法

第一步 - 设置测试工具

  1. 向 UI 测试目标添加一个新的 XCTestCase 并导入 StanwoodUITesting

    import XCTest
    import StanwoodUITesting
    
    class StanwoodTests: XCTestCase {
    
        let app = XCUIApplication()
    
        override func setUp() {
            super.setUp()
    
        }
    
        override func tearDown() {
            // Put teardown code here. This method is called after the invocation of each test method in the class.
            super.tearDown()
        }
    }
  2. 让我们配置并启动 SDK

    将以下内容添加到 setUp() 函数中

    let app = XCUIApplication()
    var testingManager: UITesting.Manager!
    
    override func setUp() {
        	super.setUp()
    
        	continueAfterFailure = false
    
        	let slack = UITesting.Slack(webhookURL: URL(string: "webhook")!, channelName: "#channel")
        	guard let configurations = UITesting.Configurations(bundleId: "com.company.example", version: "1.0", app: app, slack: slack) else { return }
        
        	testingManager = UITesting.Manager(configurations: configurations, target: self)
        	testingManager.launch()
     }
  3. 现在我们已经准备好设置测试用例

    func testStanwood(){
    	testingManager.runTests()
    }

    testingManager.runTests() 会运行测试并报告是否有任何失败。

第二步 - 配置你的项目

概述

测试导航通过查询 XCUIElementXCUIElementQuery 类型实现。查看导航类型以获取完整列表,请参阅此处。UI 测试工具通过索引或键标识每个元素,例如

// Index
buttons.element(boundBy: index)

// Key
buttons[key]
我们需要做什么?

我们需要为每个元素设置一个 accessibilityIdentifier。这可以在 Xcode 中完成,在“身份检查器”下的工具面板中。

你现在可能感觉这个过程会花费太长时间!先别急... 这一切都会为您处理,您需要做的就是遵循以下三个简单步骤

1) Add `pod 'StanwoodCore` to your podfile
2) import StanwoodCore in any .swift files that contains UI elements
3) When setting labels/text, you have two options:
	a) Set the localised KEY in interface builder, i'e "MY_KEY_TITLE"
	b) Set `.localisedText` instead of `.text`.
	Note> It is required that you do not localise the key, rather then pass in the key. This will get handled by StanwoodCore

StanwoodCore 全部文档

PM 使用方法

概述

UI测试工具通过查询视图层次结构中的元素类型,可以通过调用自定义键或索引来访问它们。例如,如果我们查看develop.apple.com上的以下图像,我们可以看到元素是如何布局的。

View Hierchy

这是一个很好的例子,我们有一个顶部的UIView,可以通过键来识别,还有一个UICellectionView,可以通过索引识别其单元格。

创建我们的第一个测试用例

  1. 首先,我们想要设置JSON格式的架构

    {
    	"test_cases" : [
    
    	]
    }
  2. 创建测试用例

    {
    	"test_cases": [
    		"id" : "1",
    		"title": "Images Test",
    		"description": "Testing if the fifth image is tappable"
    	]
    }
  3. 设置navigation动作以支持测试用例

    导航是一组导航动作。我们需要设置导航项到我们想要测试的位置。例如,让我们根据上面的例子设置导航项。

    让我们假设这个视图已经打开

    • 第二个标签可以通过索引1的tabs访问

    • 并且图像视图可以通过在标签的rootView中的按钮处 taps 以pierIdentifier标识符访问

    • 第五张图像可以通过索引4的cells访问

       {
       	"test_cases": [
       		"id" : "1",
       		"title": "Images Test",
       		"description": "Testing if the fifth image is tappable",
       		"navigation" : [
       			"tabs[1].action.tap",
       			"buttons['pierIdentifier'].action.tap",
       			"cells[4].action.tap"
       		]
       	]
       }
  4. 现在,假设我们想测试的第11个位置的图像,这个视图无法访问,我们可以设置不同的动作,如swipeUp, swipeDown。例如

    {
    	"test_cases": [
    		"id": "1",
    		"title": "Images Test",
    		"description": "Testing if the fifth image is tappable",
    		"navigation": [
    			"tabs[1].action.tap",
    			"buttons['pierIdentifier'].action.tap",
    			"cells[4].action.swipeUp",
    			"cells[10].action.tap"
    		]
    	]
    }

完整的动作列表请参阅此处

完整的导航类型请参阅此处。UI测试工具通过索引或键识别每个元素。

注意:元素标识符将列在每个项目的文档中的“UI测试标识符”部分

系统提示

StanwoodUITesting支持系统提示。要监控系统提示,只需添加.monitor到任何导航句柄。

	{
		"test_cases": [
			"id": "1",
			"title": "Images Test",
			"description": "Testing if the fifth image is tappable",
			"navigation": [
				"tabs[1].action.tap",
				"buttons['pierIdentifier'].action.tap.monitor",
				"cells[4].action.swipeUp",
				"cells[10].action.tap.monitor"
			]
		]
	}

屏幕截图

已经集成并添加到动作列表。要获取屏幕截图,请添加action.screenshot

要启用截图功能,请将环境变量添加到方案中 名称: SRCROOT,值: ${SRCROOT}

	{
		"test_cases": [
			"id": "1",
			"title": "Images Test",
			"description": "Testing if the fifth image is tappable",
			"navigation": [
				"action.screenshot",
				"tabs[1].action.tap",
				"buttons['pierIdentifier'].action.tap.monitor",
				"cells[4].action.swipeUp",
				"action.screenshot",
				"cells[10].action.tap.monitor"
			]
		]
	}

发行说明

0.1.5

  • 添加对navigationBar的支持
  • 改进错误处理
  • 删除一些未使用的键

许可

StanwoodUITesting遵循MIT许可。有关更多信息,请参阅LICENSE文件。