google/EarlGrey

Undefined symbol: _OBJC_CLASS_$_GREYActionBlock

christianmierez opened this issue · 1 comments

I am implementing some functional UI tests using EarlGrey 2 where I need to get the text value of an element and check if it matches with X string. I followed this example but I am getting this error when running the UI test:

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_GREYActionBlock", referenced from: objc-class-ref in GetText.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here's the method for getting the text from label

public class Element {
  var text = ""
}

func grey_getText(_ elementCopy: Element) -> GREYActionBlock {
  return GREYActionBlock.action(withName: "get text", constraints: grey_respondsToSelector(#selector(getter: UILabel.text))) { element, errorOrNil -> Bool in
    let elementObject = element as? NSObject
    let text = elementObject?.perform(#selector(getter: UILabel.text), with: nil)?.takeUnretainedValue() as? String
    elementCopy.text = text ?? ""
    return true
  }
}

method call:

lazy var usernameText = EarlGrey.selectElement(with: grey_accessibilityID("username-label"))

func getUsername() -> String {
    let element = Element()
    usernameText.perform(grey_getText(element))
    return element.text
 }
  
 func isUserLoggedIn(username: String) -> Self {
    userProfileDrawer.perform(grey_tap())
    GREYAssert(getUsername() == "u/\(username)", "Username: \(username) did not upload correctly")
    return self
 }

Am I missing something? Thanks in advance!

Were you able to fix it?