google / google/EarlGrey

EarlGrey() has wrong line number for page objects

Open
#95 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
Objective-C
Stars
5.7k
Forks
737
Avg merge
1d 20h
Merged PRs (30d)
5

Description

In `EarlGrey.swift`, EarlGrey is defined as:

``` swift
public func EarlGrey() -> EarlGreyImpl! {
return EarlGreyImpl.invokedFromFile(#file, lineNumber: #line)
}
```

I define a login page object:

``` swift
public class LoginPage {

//# MARK: - Login Page Elements

private var domainField: GREYElementInteraction {
return EarlGrey().selectElementWithMatcher(grey_accessibilityID("domain_field"))
}
```

which is then used:

``` swift
func assertPageObjects() {
domainField.assertWithMatcher(grey_sufficientlyVisible())
}
```

The line number is wrong because `EarlGrey()` sets it to be on the `EarlGrey().selectElementWithMatcher...` line.

I've had to update `EarlGrey.swift` like this:

``` swift
//# MARK: - Custom EarlGrey file/line

extension EarlGreyImpl {
// Use @nonobjc to fix A declaration cannot be both 'final' and 'dynamic' error
@nonobjc public static var file: String = ""
@nonobjc public static var line: UInt = 0

public static func setFromFile(file: String, _ line: UInt) {
self.file = file
self.line = line
}
}

public func grey_invokedFromFile(file: String, _ line: UInt) {
EarlGreyImpl.setFromFile(file, line)
}

public func EarlGrey() -> EarlGreyImpl! {
return EarlGreyImpl.invokedFromFile(EarlGreyImpl.file, lineNumber: EarlGreyImpl.line)
}
```

and update the page object:

``` swift
func assertPageObjects(file: String = #file, _ line: UInt = #line) {
grey_invokedFromFile(file, line)

domainField.assertWithMatcher(grey_sufficientlyVisible())
}
```

now the line number is correctly identified in the test. Thoughts on how to best update `EarlGrey.swift` to handle this use case?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.