Fastlane截图失败

时间:2016-07-26 11:53:57

标签: ios swift fastlane

我正试图用fastlane截取屏幕截图。此刻我不需要发送到iTunes。我只是想截取屏幕截图,但我得到“测试失败”。

有我的Snapfile:

# A list of devices you want to take the screenshots from
devices([
   "iPhone 6",
   "iPhone 6 Plus",
   "iPhone 5s",
   "iPhone 4s",
])

languages([
  “pt”
])

# The name of the scheme which contains the UI Tests
scheme “Consultor”

# Where should the resulting screenshots be stored?
output_directory "./screenshots"

clear_previous_screenshots true # remove the '#' to clear all previously generated screenshots before creating new ones

# Choose which project/workspace to use
workspace “././Consultor.xcworkspace"

并且有我的fastfile:

        # Customise this file, documentation can be found here:
    # https://github.com/fastlane/fastlane/tree/master/fastlane/docs
    # All available actions: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Actions.md
    # can also be listed using the `fastlane actions` command

    # Change the syntax highlighting to Ruby
    # All lines starting with a # are ignored when running `fastlane`

    # If you want to automatically update fastlane if a new version is available:
    # update_fastlane

    # This is the minimum version number required.
    # Update this, if you use features of a newer version
    fastlane_version "1.88.0"

    default_platform :ios

    platform :ios do
      before_all do
        # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
        cocoapods

      end

      desc "Runs all the tests"
      lane :test do
        scan
      end


  desc "Take screenshots"
  lane :screenshot do
    snapshot
  end



  desc "Submit a new Beta Build to Apple TestFlight"
  desc "This will also make sure the profile is up to date"
  lane :beta do
    # match(type: "appstore") # more information: https://codesigning.guide
    gym # Build your app - more options available
    pilot

    # sh "your_script.sh"
    # You can also use other beta testing services here (run `fastlane actions`)
  end

  desc "Deploy a new version to the App Store"
  lane :appstore do
    # match(type: "appstore")
    # snapshot
    gym # Build your app - more options available
    deliver(force: true)
    # frameit
  end

  # You can define as many lanes as you want

  after_all do |lane|
    # This block is called, only if the executed lane was successful

    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end

  error do |lane, exception|
    # slack(
    #   message: exception.message,
    #   success: false
    # )
  end
end


# More information about multiple platforms in fastlane: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
# All available actions: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Actions.md

# fastlane reports which actions are used
# No personal data is recorded. Learn more at https://github.com/fastlane/enhancer

我的项目是在swift中编写的,而我的测试类:ConsultorUITests:

    //
//  SnapshotHelper.swift
//  Example
//
//  Created by Felix Krause on 10/8/15.
//  Copyright © 2015 Felix Krause. All rights reserved.
//

import Foundation
import XCTest

var deviceLanguage = ""
var locale = ""

@available(*, deprecated, message="use setupSnapshot: instead")
func setLanguage(app: XCUIApplication) {
    setupSnapshot(app)
}

func setupSnapshot(app: XCUIApplication) {
    Snapshot.setupSnapshot(app)
}

func snapshot(name: String, waitForLoadingIndicator: Bool = true) {
    Snapshot.snapshot(name, waitForLoadingIndicator: waitForLoadingIndicator)
}

public class Snapshot: NSObject {

    public class func setupSnapshot(app: XCUIApplication) {
        setLanguage(app)
        setLocale(app)
        setLaunchArguments(app)
    }

    class func setLanguage(app: XCUIApplication) {
        guard let prefix = pathPrefix() else {
            return
        }

        let path = prefix.stringByAppendingPathComponent("language.txt")

        do {
            let trimCharacterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
            deviceLanguage = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding).stringByTrimmingCharactersInSet(trimCharacterSet) as String
            app.launchArguments += ["-AppleLanguages", "(\(deviceLanguage))"]
        } catch {
            print("Couldn't detect/set language...")
        }
    }

    class func setLocale(app: XCUIApplication) {
        guard let prefix = pathPrefix() else {
            return
        }

        let path = prefix.stringByAppendingPathComponent("locale.txt")

        do {
            let trimCharacterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
            locale = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding).stringByTrimmingCharactersInSet(trimCharacterSet) as String
        } catch {
            print("Couldn't detect/set locale...")
        }
        if locale.isEmpty {
            locale = NSLocale(localeIdentifier: deviceLanguage).localeIdentifier
        }
        app.launchArguments += ["-AppleLocale", "\"\(locale)\""]
    }

    class func setLaunchArguments(app: XCUIApplication) {
        guard let prefix = pathPrefix() else {
            return
        }

        let path = prefix.stringByAppendingPathComponent("snapshot-launch_arguments.txt")
        app.launchArguments += ["-FASTLANE_SNAPSHOT", "YES", "-ui_testing"]

        do {
            let launchArguments = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding) as String
            let regex = try NSRegularExpression(pattern: "(\\\".+?\\\"|\\S+)", options: [])
            let matches = regex.matchesInString(launchArguments, options: [], range: NSRange(location:0, length:launchArguments.characters.count))
            let results = matches.map { result -> String in
                (launchArguments as NSString).substringWithRange(result.range)
            }
            app.launchArguments += results
        } catch {
            print("Couldn't detect/set launch_arguments...")
        }
    }

    public class func snapshot(name: String, waitForLoadingIndicator: Bool = true) {
        if waitForLoadingIndicator {
            waitForLoadingIndicatorToDisappear()
        }

        print("snapshot: \(name)") // more information about this, check out https://github.com/fastlane/fastlane/tree/master/snapshot

        sleep(1) // Waiting for the animation to be finished (kind of)
        XCUIDevice.sharedDevice().orientation = .Unknown
    }

    class func waitForLoadingIndicatorToDisappear() {
        let query = XCUIApplication().statusBars.childrenMatchingType(.Other).elementBoundByIndex(1).childrenMatchingType(.Other)

        while (0..<query.count).map({ query.elementBoundByIndex($0) }).contains({ $0.isLoadingIndicator }) {
            sleep(1)
            print("Waiting for loading indicator to disappear...")
        }
    }

    class func pathPrefix() -> NSString? {
        if let path = NSProcessInfo().environment["SIMULATOR_HOST_HOME"] as NSString? {
            return path.stringByAppendingPathComponent("Library/Caches/tools.fastlane")
        }
        print("Couldn't find Snapshot configuration files at ~/Library/Caches/tools.fastlane")
        return nil
    }
}

extension XCUIElement {
    var isLoadingIndicator: Bool {
        return self.frame.size == CGSize(width: 10, height: 20)
    }
}

// Please don't remove the lines below
// They are used to detect outdated configuration files
// SnapshotHelperVersion [1.2]

最后,终端记录:

  

`▸构建窗格/ Alamofire [调试]▸检查依赖关系▸构建   窗格/光泽[调试]▸检查依赖关系▸构建窗格/ JGProgressHUD   [调试]▸检查依赖关系▸构建窗格/窗格 - 顾问[调试]▸   检查依赖关系▸建立咨询员/咨询员[调试]▸检查   依赖关系▸运行脚本'Check PodsManifest.lock'▸运行   脚本'嵌入窗格框架'▸运行脚本'复制窗格资源'   ▸运行脚本'运行脚本'▸构建Consultor / ConsultorTests   [调试]▸检查依赖关系▸构建咨询人员/咨询人员   [调试]▸检查依赖关系▸编译ConsultorUITests.swift▸   链接ConsultorUITests▸生成'ConsultorUITests.xctest.dSYM'▸   感动ConsultorUITests.xctest   **测试失败**

     

所有测试[08:49:30]:退出状态:65 [08:49:30]:测试失败 - 检查   超出上面的日志[08:49:30]:测试失败,重新尝试2中的1   times`

0 个答案:

没有答案