View Code? Open in Web Editor
NEW
Einstein is an UITest framework that integrates the logic across the Project and UITest through AccessibilityIdentified. And in UITest, using it to better support test code writing.
Home Page: https://zhipingyang.github.io/Einstein/
License: MIT License
Swift 94.33%
Ruby 4.57%
Objective-C 0.90%
Shell 0.19%
einstein's People
Contributors
Watchers
einstein's Issues
๐ค
Here is two extensions PrettyRawRepresentable+helpers.swift and RawRepresentable+helpers.swift which are support different situation on enum.
But the most unacceptable thing is that their API is almost the same
enum WayOne : String , PrettyRawRepresentable {
case theWay
}
enum WayTwo : String {
case theWay
}
wayOneView >>> WayOne . theWay
wayTwoView >>> WayTwo . theWay
// wayOneView.accessibilityIdentifier == "WayOne_theWay"
// called in PrettyRawRepresentable+helpers.swift
let element_1 : XCUIElement = WayOne . theWay. element
// wayTwoView.accessibilityIdentifier == "theWay"
// called in RawRepresentable+helpers.swift
let element_2 : XCUIElement = WayTwo . theWay. element
current
public protocol PrettyRawRepresentable : RawRepresentable where RawValue == String {
var prettyRawValue : RawValue { get }
}
public extension PrettyRawRepresentable {
var prettyRawValue : String {
let paths = String ( reflecting: self ) . split ( separator: " . " ) . dropFirst ( )
if String ( paths. last ?? " " ) != rawValue {
return rawValue
}
return paths. joined ( separator: " _ " )
}
}
infix operator >>>
public func >>> < T : RawRepresentable > ( lhs: UIAccessibilityIdentification ? , rhs: T ) where T. RawValue == String {
lhs? . accessibilityIdentifier = rhs. rawValue
}
public func >>> < T : PrettyRawRepresentable > ( lhs: UIAccessibilityIdentification ? , rhs: T ) {
lhs? . accessibilityIdentifier = rhs. prettyRawValue
}
wants the design
only use one function
public protocol PrettyRawRepresentable : RawRepresentable where RawValue == String {
var rawValue : RawValue { get }
}
public extension PrettyRawRepresentable {
var rawValue : String {
// how todo
}
}
infix operator >>>
public func >>> < T : RawRepresentable > ( lhs: UIAccessibilityIdentification ? , rhs: T ) where T. RawValue == String {
lhs? . accessibilityIdentifier = rhs. rawValue
}
PredicateRawValue is RawValue type of EasyPredicate
current
public enum PredicateRawValue : RawRepresentable {
public var rawValue : String { return xxx }
public init ? ( rawValue: String ) {
self = . custom( regular: rawValue)
}
case bool( key: PredicateKey . bool , comparison: Comparison , value: Bool )
case string( key: PredicateKey . string , comparison: Comparison , value: String )
case type( value: XCUIElement . ElementType )
case custom( regular: String )
}
the thinking of new design
enum PredicateRawValue < Key : RawRepresentable , Value : RawRepresentable > : RawRepresentable where Key. RawValue == String {
var rawValue : String { return xxx }
init ? ( rawValue: String ) {
self = . custom( regular: rawValue)
}
case keyValue( key: Key , comparison: Comparison , value: Value )
case custom( regular: String ) // unrelated with Key & Value define, shit ๐ฉ
}
public protocol PrettyRawRepresentable : RawRepresentable where RawValue == String {
var prettyRawValue : RawValue { get }
}
public extension PrettyRawRepresentable {
var prettyRawValue : String {
let paths = String ( reflecting: self ) . split ( separator: " . " ) . dropFirst ( )
if String ( paths. last ?? " " ) != rawValue {
return rawValue
}
return paths. joined ( separator: " _ " )
}
}
As we already defined PrettyRawRepresentable's RawValue == String
,
but enum cannot write as blow, why?
enum Home : PrettyRawRepresentable {
case setting
}
let str = Home . seeting. prettyRawValue // Home_setting
current
enum Home : String , PrettyRawRepresentable {
case setting
}
let str = Home . seeting. prettyRawValue // Home_setting
wants
enum Home : XXX {
case setting
}
let str = Home . seeting. prettyRawValue // Home_setting
XXX
can be a protocol or a struct, but should better as a subprotocol of RawRepresentable
XXX
method already be achieved (no more code as the blow)
see more: AccessibilityIdentifier