From 9fe6568b17393eafd36347ddc9d3d5af09a033ed Mon Sep 17 00:00:00 2001 From: Doron Pearl Date: Mon, 10 Oct 2016 14:36:07 -0400 Subject: [PATCH 1/2] added match by type --- detox/ios/Detox/GREYMatchers+Detox.h | 2 ++ detox/ios/Detox/GREYMatchers+Detox.m | 6 ++++++ detox/src/ios/expect.js | 12 +++++++++++- detox/test/e2e/b-matchers.js | 6 ++++++ detox/test/package.json | 4 ++-- detox/test/src/Screens/MatchersScreen.js | 12 ++++++++++++ detox/test/src/assets/star.png | Bin 0 -> 2096 bytes 7 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 detox/test/src/assets/star.png diff --git a/detox/ios/Detox/GREYMatchers+Detox.h b/detox/ios/Detox/GREYMatchers+Detox.h index 474ec4cfa7..c6c77c9bef 100644 --- a/detox/ios/Detox/GREYMatchers+Detox.h +++ b/detox/ios/Detox/GREYMatchers+Detox.h @@ -18,4 +18,6 @@ + (id)detoxMatcherForNot:(id)matcher; ++ (id)detoxMatcherForClass:(NSString *)aClassName; + @end diff --git a/detox/ios/Detox/GREYMatchers+Detox.m b/detox/ios/Detox/GREYMatchers+Detox.m index 60f91bc35e..f186d0647f 100644 --- a/detox/ios/Detox/GREYMatchers+Detox.m +++ b/detox/ios/Detox/GREYMatchers+Detox.m @@ -47,4 +47,10 @@ @implementation GREYMatchers (Detox) return grey_not(matcher); } ++ (id)detoxMatcherForClass:(NSString *)aClassName +{ + Class klass = NSClassFromString(aClassName); + return grey_kindOfClass(klass); +} + @end diff --git a/detox/src/ios/expect.js b/detox/src/ios/expect.js index 269660a758..46ea75e400 100644 --- a/detox/src/ios/expect.js +++ b/detox/src/ios/expect.js @@ -42,6 +42,15 @@ class IdMatcher extends Matcher { } } +class TypeMatcher extends Matcher { + constructor(value) { + super(); + if (typeof value !== 'string') throw new Error(`TypeMatcher ctor argument must be a string, got ${typeof value}`); + this._call = invoke.call(invoke.IOS.Class('GREYMatchers'), 'detoxMatcherForClass:', value); + } +} + + class VisibleMatcher extends Matcher { constructor() { super(); @@ -358,7 +367,8 @@ function element(matcher) { const by = { label: (value) => new LabelMatcher(value), - id: (value) => new IdMatcher(value) + id: (value) => new IdMatcher(value), + type: (value) => new TypeMatcher(value) }; const exportGlobals = function () { diff --git a/detox/test/e2e/b-matchers.js b/detox/test/e2e/b-matchers.js index 125ea16ede..d8ce6d4349 100644 --- a/detox/test/e2e/b-matchers.js +++ b/detox/test/e2e/b-matchers.js @@ -18,4 +18,10 @@ describe('Matchers', function () { expect(element(by.label('ID Working!!!'))).toBeVisible(); }); + it.only('should match elements by type', function () { + expect(element(by.type('RCTImageView'))).toBeVisible(); + element(by.type('RCTImageView')).tap(); + expect(element(by.type('RCTImageView'))).toBeNotVisible(); + }); + }); diff --git a/detox/test/package.json b/detox/test/package.json index 19480966de..9c7b6601cb 100644 --- a/detox/test/package.json +++ b/detox/test/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "lodash": "^4.14.1", - "react": "15.1.0", - "react-native": "^0.27.2" + "react": "15.2.1", + "react-native": "0.31.0" }, "devDependencies": { "detox": "file:..", diff --git a/detox/test/src/Screens/MatchersScreen.js b/detox/test/src/Screens/MatchersScreen.js index e32fd289f5..a8c2c0aa70 100644 --- a/detox/test/src/Screens/MatchersScreen.js +++ b/detox/test/src/Screens/MatchersScreen.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import { Text, View, + Image, TouchableOpacity } from 'react-native'; @@ -27,6 +28,11 @@ export default class MatchersScreen extends Component { ID + {!this.state.hideStar ? + + + : null} + ); } @@ -47,4 +53,10 @@ export default class MatchersScreen extends Component { }); } + onStarPress() { + this.setState({ + hideStar: true + }); + } + } diff --git a/detox/test/src/assets/star.png b/detox/test/src/assets/star.png new file mode 100644 index 0000000000000000000000000000000000000000..26d043abfd391c2ed4fee46e650014811f334ca7 GIT binary patch literal 2096 zcmeH{={FP#7{-UeAjTMD-zG~4Axn0~5(Z;3Bv}e$$3~{$@pUEG?dQdEKX> zUQ!HY>$L39@u6Un)}0CaN}?>{A^;u?Sd<8-isfs=n;bq`LSTSfS|I053#mqCCA!sR;49btGzphe{^L|TI>QQ*Wzw$ z?+dLPjcafp&(epJ5OkM)*2}2d?XOffSG)xB2QL>sAf47N6E?Yey*=mK9st0RX=jCS ziJ)xE9(cf9#XwtC5P@Ud9M#+|noy`(c~^!xdtxR}LHvhu9&WXCo^oZ;WpEwtjx%gn z?WwIC(*Awrqv@7MQ?f2;!>>n6=1o>&RvgIM)Jron`^LsbH2nT(Rv*D8SH>iYzAB!Z znmTCiWL&47yTYg8qprsV`Gdce!6E)TYYt-0fuxREG9 z?x=JUHrX8gL`vDQM5&Y%P^F1ZF;>PD1QuG$6trE0tooPZbbXCy43LC5x1@M)#SC{< zj)EG#VbKK@ctL{@AS#RMRyIDt* zDqh>r1M67So;f)|&6xEpTIf}Dmpf&Rj5UH++@MXluLekR*9iKlaCCVc|KP`WG&*&9=X z8VQ~Brb0yIVIa`ezep4RD-?)!07CG)j$EDZFLc(ZTnTCj#A)X|g`qKW+nyN1K2k!Vr^8E~j_vCb@@!tfG(0JB!nHYt!zy<LL(1Du{!P zE-aud!baB>ScR~!vI~$vpC;dQkb1en%oG8-y8bFuHV7uwnoNAtq{*aeSVr^Kb<-q} zcH-rq+VUC!cN-@dBIC4w0$I`<+SBm}zv1rSn4?IBR>5{(!3PfL?!eobrP@IEjCn|d zlJ(knK7~{#n|0`2=b04q6}iBMD1#Q+vnAJ9yg(q#NR19dSjnwX{}%s=TmqpC%h;mb zs&Xm=dhNWz+8sZfF;p> zC^mQ_k5+HbikZy#8KjsNv*ANr-}dkbkJDZ(fHT^LHsd;Y%Ymn-SH@RRRtwt1oK}pj91u@S%xfjzI3-r T%%o=E@6NZgMp-plTu%HKZlkvz literal 0 HcmV?d00001 From a67e17c55b5015c23ae2f641bef174d0fc7ac30f Mon Sep 17 00:00:00 2001 From: Doron Pearl Date: Mon, 10 Oct 2016 14:38:44 -0400 Subject: [PATCH 2/2] it's not the only one --- detox/test/e2e/b-matchers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detox/test/e2e/b-matchers.js b/detox/test/e2e/b-matchers.js index d8ce6d4349..d7e58d6a50 100644 --- a/detox/test/e2e/b-matchers.js +++ b/detox/test/e2e/b-matchers.js @@ -18,7 +18,7 @@ describe('Matchers', function () { expect(element(by.label('ID Working!!!'))).toBeVisible(); }); - it.only('should match elements by type', function () { + it('should match elements by type', function () { expect(element(by.type('RCTImageView'))).toBeVisible(); element(by.type('RCTImageView')).tap(); expect(element(by.type('RCTImageView'))).toBeNotVisible();