google/EarlGrey

Is there any example on doing screenshot in Swift api?

impvd opened this issue · 1 comments

impvd commented

Google search yields this repo https://github.com/elpassion/EarlGreySnapshots , but it seems they don't maintain it anymore(The last commit was 4 years ago).

There're some examples relate to screenshot, could anyone help to give some suggestion on migrating these Object-C examples to Swift?

For example(From setup doc):

class MyFirstEarlGreyTest: XCTestCase {

  func testExample() {
    let application: XCUIApplication = XCUIApplication()
    application.launch()
    // HOW TO SCREENSHOT HERE
    EarlGrey.selectElement(with: grey_keyWindow())
      .perform(grey_tap())
  }
}

I had tried perfecto's samples:

let confpath = GREYConfiguration.sharedInstance().value(forConfigKey: kGREYConfigKeyArtifactsDirLocation) as! String
var screenshot = GREYScreenshotUtil.takeScreenshotForAppStore()
var filename = String(describing: EarlGreySimpleIosAppForTestingTests.self) + "#" + #function + ".png"
GREYScreenshotUtil.saveImage(asPNG: screenshot, toFile: filename, inDirectory: confpath)
EarlGrey.select(elementWithMatcher: grey_text("EarlGrey Tests")).assert(grey_sufficientlyVisible())

Which got lots of errors:
image

Is this EarlGrey 1.0? That is not supported anymore.

Here is a Snapshot Example for EarlGrey 2.0.

https://github.com/google/EarlGrey/blob/earlgrey2/Tests/Functional/Sources/Swift/SwiftTests.swift#L315