1
- /*
2
- * Copyright 2016 , Optimizely
3
- * <p/>
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- * <p/>
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- * <p/>
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
1
+ /****************************************************************************
2
+ * Copyright 2017 , Optimizely, Inc. and contributors *
3
+ * *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); *
5
+ * you may not use this file except in compliance with the License. *
6
+ * You may obtain a copy of the License at *
7
+ * *
8
+ * http://www.apache.org/licenses/LICENSE-2.0 *
9
+ * *
10
+ * Unless required by applicable law or agreed to in writing, software *
11
+ * distributed under the License is distributed on an "AS IS" BASIS, *
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13
+ * See the License for the specific language governing permissions and *
14
+ * limitations under the License. *
15
+ *************************************************************************** /
16
16
package com .optimizely .ab .android .test_app ;
17
17
18
18
import android .app .AlarmManager ;
47
47
import static android .support .test .espresso .Espresso .onView ;
48
48
import static android .support .test .espresso .action .ViewActions .click ;
49
49
import static android .support .test .espresso .assertion .ViewAssertions .matches ;
50
+ import static android .support .test .espresso .matcher .ViewMatchers .isDisplayed ;
50
51
import static android .support .test .espresso .matcher .ViewMatchers .withId ;
51
52
import static android .support .test .espresso .matcher .ViewMatchers .withText ;
52
53
import static junit .framework .Assert .assertFalse ;
@@ -62,7 +63,7 @@ public class MainActivityEspressoTest {
62
63
private ServiceScheduler serviceScheduler ;
63
64
private Intent dataFileServiceIntent , eventIntentService ;
64
65
65
- private ActivityTestRule <MainActivity > activityTestRule = new ActivityTestRule <>(MainActivity .class );
66
+ private ActivityTestRule <SplashScreenActivity > activityTestRule = new ActivityTestRule <>(SplashScreenActivity .class );
66
67
@ Rule public TestRule chain = RuleChain
67
68
.outerRule (new ExternalResource () {
68
69
@ Override
@@ -148,46 +149,32 @@ protected void after() {
148
149
public void experimentActivationForWhitelistUser () throws InterruptedException {
149
150
// Check that the text was changed.
150
151
// These tests are pointed at a real project.
151
- // The user 'test_user` is in the whitelist for variation 1 for experiment 0 and experiment 1.
152
- onView (withId (R .id .button_1 ))
153
- .check (matches (withText ( context . getString ( R . string . main_act_button_1_text_var_1 ) )));
152
+ // The user 'test_user` is in the whitelist for variation_a for experiment background_experiment
153
+ onView (withId (R .id .tv_variation_a_text_1 ))
154
+ .check (matches (isDisplayed ( )));
154
155
155
156
// Espresso will wait for Optimizely to start due to the registered idling resources
156
- onView (withId (R .id .text_view_1 ))
157
- .check (matches (withText (context .getString (R .string .main_act_text_view_1_var_1 ))));
158
-
159
157
assertTrue (serviceScheduler .isScheduled (dataFileServiceIntent ));
160
158
161
- onView (withId (R .id .button_1 )) // withId(R.id.my_view) is a ViewMatcher
162
- .perform (click ()); // click() is a ViewAction
163
-
164
- onView (withId (R .id .text_view_1 ))
165
- .check (matches (withText (context .getString (R .string .secondary_frag_text_view_1_var_1 ))));
166
-
167
- onView (withId (R .id .button_1 )) // withId(R.id.my_view) is a ViewMatcher
168
- .perform (click ()); // click() is a ViewAction
159
+ onView (withId (R .id .btn_variation_conversion )) // withId(R.id.my_view) is a ViewMatcher
160
+ .perform (click ()); // click() is a ViewAction
169
161
170
162
List <Pair <String , String >> events = CountingIdlingResourceManager .getEvents ();
171
- assertTrue (events .size () == 6 );
163
+ assertTrue (events .size () == 2 );
172
164
Iterator <Pair <String , String >> iterator = events .iterator ();
173
165
while (iterator .hasNext ()) {
174
166
Pair <String , String > event = iterator .next ();
175
167
final String url = event .first ;
176
168
final String payload = event .second ;
177
- if (url .equals ("https://logx.optimizely.com/log/decision" ) && payload .contains ("7676481120" ) && payload .contains ("7661891902" )
178
- || url .equals ("https://logx.optimizely.com/log/decision" ) && payload .contains ("7651112186" ) && payload .contains ("7674261140" )
179
- || url .equals ("https://logx.optimizely.com/log/event" ) && payload .contains ("experiment_0" )
180
- || url .equals ("https://logx.optimizely.com/log/event" ) && payload .contains ("experiment_1" )
181
- || url .equals ("https://logx.optimizely.com/log/decision" ) && payload .contains ("7680080715" ) && payload .contains ("7685562539" )
182
- || url .equals ("https://logx.optimizely.com/log/event" ) && payload .contains ("experiment_2" )) {
169
+ if (url .equals ("https://logx.optimizely.com/log/decision" ) && payload .contains ("8126664113" ) && payload .contains ("8146590584" )
170
+ || url .equals ("https://logx.optimizely.com/log/event" ) && payload .contains ("sample_conversion" )) {
183
171
iterator .remove ();
184
172
}
185
173
}
186
174
assertTrue (events .isEmpty ());
187
175
MyApplication myApplication = (MyApplication ) activityTestRule .getActivity ().getApplication ();
188
176
UserProfile userProfile = myApplication .getOptimizelyManager ().getUserProfile ();
189
177
// Being in the white list should override user profile
190
- assertNull (userProfile .lookup ("test_user" , "experiment_0" ));
191
- assertNull (userProfile .lookup ("test_user" , "experiment_1" ));
178
+ assertNull (userProfile .lookup ("test_user" , "background_experiment" ));
192
179
}
193
180
}
0 commit comments