Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 使用Cucumberish和UI测试从情节提要加载控制器_Swift_User Interface_Testing_Cucumber_Bdd - Fatal编程技术网

Swift 使用Cucumberish和UI测试从情节提要加载控制器

Swift 使用Cucumberish和UI测试从情节提要加载控制器,swift,user-interface,testing,cucumber,bdd,Swift,User Interface,Testing,Cucumber,Bdd,我正在尝试使用框架用BDD实现UI测试。 我非常了解功能文件解析系统,并设法测试了主屏幕的一些UI元素 但是,在相应屏幕上使用UI测试之前,我想从脚本加载任何控制器 这是我的初始化代码: @objc class CucumberishSwiftInit: NSObject { @objc class func CucumberishSwiftInit() { var application : XCUIApplication! //A closure that will be e

我正在尝试使用框架用BDD实现UI测试。 我非常了解功能文件解析系统,并设法测试了主屏幕的一些UI元素

但是,在相应屏幕上使用UI测试之前,我想从脚本加载任何控制器

这是我的初始化代码:

@objc class CucumberishSwiftInit: NSObject {
@objc class func CucumberishSwiftInit()
{
    var application : XCUIApplication!
    //A closure that will be executed just before executing any of your features
    beforeStart { () -> Void in
        application = XCUIApplication()
    }
    //A Given step definition
    Given("the app is running") { (args, userInfo) -> Void in
        application.launch()
        let bundle = Bundle.main

        // I double checked the storyboard name and I can access it in my Unit Tests target
        // application crashes here
        let storyboard = UIStoryboard(name: "Main", bundle: bundle)

        // never executed 
        Swift.print("storyboard \(storyboard)")
    }
    let bundle = Bundle(for: CucumberishSwiftInit.self)

    Cucumberish.executeFeatures(inDirectory: "Features", from: bundle, includeTags: nil, excludeTags: ["skip"])
}
}
某些功能文件:

@run @welcome
Feature: Some feature
Some feature desc

Scenario: Can load screen
    Given the app is running
    ...

应用程序在UIStoryboard init语句上崩溃,捕获到“NSInvalidArgumentException”,“在捆绑包NSBundle(已加载)中找不到名为“Main”的情节提要”。我不知道为什么,因为它正在使用我的单元测试。

您得到的错误是由于您尝试加载的
.storyboard
文件不是您正在运行的应用程序包的一部分

发生这种情况的原因是,当您运行UI测试时,您的代码并不是在与应用程序相同的进程中运行的,它只能通过
xguiapplication
代理与之交互。(机制可能略有不同,但这是要点,不幸的是,我几乎没有可以链接的文档。)

UI测试是一种与使用
xtest
不同的测试方式。无法通过编程方式从
加载屏幕实例。脚本


换句话说,您不能在UI测试中使用应用程序中的任何代码,而是必须像真实用户一样与之交互,并为屏幕上的内容编写断言。

谢谢您的帮助!因此,如果我无法访问.storyboard文件,我必须手动转到特定屏幕。这也是使用LANC的一个有趣的替代方法h参数:。如果UI测试旨在测试屏幕的内部工作,这是一种有趣的方法,因为它不知道应用程序的分段如何发展。很高兴有用@michael martinez:)链接问题中的方法很巧妙,但在支持运行UI的能力的生产代码中有大量开销测试。我鼓励任何考虑实现它的人在他们的生产代码库中增加额外代码的成本。代码是一种负担,我们写得越少越好。