From 7777a8022659760496453eb27c8806dec54a6da7 Mon Sep 17 00:00:00 2001 From: nhedley Date: Mon, 28 Aug 2017 14:46:51 -0400 Subject: [PATCH] Update Xamarin tests and run them through Travis CI (#2) * Xamarin calabash tests * Update backdoor for DFP banner tests * Update gitignore and testprebid script * Use Ruby 2.0, comment out interstitial tests, and make directory for apk --- .gitignore | 1 + .travis.yml | 2 + PrebidMobile/DemoApp/build.gradle | 4 - .../prebid/mobile/demoapp/DemoActivity.java | 6 ++ .../dfpdemofragments/DFPBannerFragment.java | 23 ++++ .../DFPInterstitialFragment.java | 1 + PrebidMobile/IntegrationTests/Gemfile | 6 ++ PrebidMobile/IntegrationTests/Gemfile.lock | 101 ++++++++++++++++++ .../features/base_test.feature | 37 +++++-- .../step_definitions/calabash_steps.rb | 33 ++++-- .../IntegrationTests/run_tests_local.sh | 5 +- testprebid.sh | 10 +- 12 files changed, 206 insertions(+), 23 deletions(-) create mode 100644 PrebidMobile/IntegrationTests/Gemfile create mode 100644 PrebidMobile/IntegrationTests/Gemfile.lock diff --git a/.gitignore b/.gitignore index 542a5eff4..10b820011 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Calabash Test .irb-history +screenshot_* # System .DS_Store diff --git a/.travis.yml b/.travis.yml index 57a395677..c1f934796 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,5 +23,7 @@ android: jdk: - oraclejdk8 +before_install: + - rvm install 2.0.0 script: - ./testprebid.sh diff --git a/PrebidMobile/DemoApp/build.gradle b/PrebidMobile/DemoApp/build.gradle index 2dffc9174..f5629bbff 100644 --- a/PrebidMobile/DemoApp/build.gradle +++ b/PrebidMobile/DemoApp/build.gradle @@ -27,10 +27,6 @@ android { } } -repositories { - jcenter() -} - dependencies { compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.google.android.gms:play-services-ads:10.2.0' diff --git a/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/DemoActivity.java b/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/DemoActivity.java index cddb87081..2222a02ed 100644 --- a/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/DemoActivity.java +++ b/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/DemoActivity.java @@ -44,6 +44,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { } + // This is used in the calabash tests to grab the obfuscated web view class name from DFP + public String getDFPWebViewName() { + DFPBannerFragment fragment = (DFPBannerFragment) getSupportFragmentManager().findFragmentById(R.id.demoRoot); + return fragment.getDFPWebViewName(); + } + @Override protected void onDestroy() { super.onDestroy(); diff --git a/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/dfpdemofragments/DFPBannerFragment.java b/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/dfpdemofragments/DFPBannerFragment.java index 39b01c866..366d29745 100644 --- a/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/dfpdemofragments/DFPBannerFragment.java +++ b/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/dfpdemofragments/DFPBannerFragment.java @@ -6,6 +6,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.webkit.WebView; import android.widget.Button; import android.widget.FrameLayout; @@ -74,6 +75,7 @@ public void onAdLoaded() { LogUtil.d("DPF-Banner", "onAdLoaded"); } }; + return root; } @@ -93,7 +95,28 @@ private void setupBannerWithoutWait() { adView1.loadAd(request); } + + public String getDFPWebViewName() { + int count = adView2.getChildCount(); + for (int i = 0; i < count; i++) { + ViewGroup nextChild = (ViewGroup) adView2.getChildAt(i); + int secondCount = nextChild.getChildCount(); + for (int j = 0; j < secondCount; j++) { + ViewGroup thirdChild = (ViewGroup) nextChild.getChildAt(j); + int thirdCount = thirdChild.getChildCount(); + for (int k = 0; k < thirdCount; k++) { + System.out.println(thirdChild.getChildAt(k)); + if (thirdChild.getChildAt(k) instanceof WebView) { + return thirdChild.getChildAt(k).getClass().getName(); + } + } + } + } + return "undefined"; + } + private void setupBannerWithWait(final int waitTime) { + FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame2); adFrame.removeAllViews(); adView2 = new PublisherAdView(getActivity()); diff --git a/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/dfpdemofragments/DFPInterstitialFragment.java b/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/dfpdemofragments/DFPInterstitialFragment.java index 843fc97e7..099a5aee7 100644 --- a/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/dfpdemofragments/DFPInterstitialFragment.java +++ b/PrebidMobile/DemoApp/src/main/java/org/prebid/mobile/demoapp/dfpdemofragments/DFPInterstitialFragment.java @@ -6,6 +6,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.webkit.WebView; import android.widget.Button; import com.google.android.gms.ads.AdListener; diff --git a/PrebidMobile/IntegrationTests/Gemfile b/PrebidMobile/IntegrationTests/Gemfile new file mode 100644 index 000000000..dbe12a98f --- /dev/null +++ b/PrebidMobile/IntegrationTests/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gem "xamarin-test-cloud" +gem "calabash-android" +gem "calabash-cucumber" +gem "rspec" diff --git a/PrebidMobile/IntegrationTests/Gemfile.lock b/PrebidMobile/IntegrationTests/Gemfile.lock new file mode 100644 index 000000000..91febeebf --- /dev/null +++ b/PrebidMobile/IntegrationTests/Gemfile.lock @@ -0,0 +1,101 @@ +GEM + remote: https://rubygems.org/ + specs: + CFPropertyList (2.3.5) + awesome_print (1.8.0) + builder (3.2.3) + calabash-android (0.9.0) + awesome_print (~> 1.2) + cucumber + escape (~> 0.0.4) + httpclient (>= 2.7.1, < 3.0) + json (~> 1.8) + luffa + rubyzip (~> 1.1) + slowhandcuke (~> 0.0.3) + calabash-cucumber (0.20.5) + awesome_print + bundler (~> 1.3) + clipboard (~> 1.0) + cucumber + edn (>= 1.0.6, < 2.0) + geocoder (>= 1.1.8, < 2.0) + httpclient (>= 2.7.1, < 3.0) + json + run_loop (>= 2.4.1, < 3.0) + slowhandcuke (~> 0.0.3) + clipboard (1.1.1) + command_runner_ng (0.1.3) + cucumber (2.4.0) + builder (>= 2.1.2) + cucumber-core (~> 1.5.0) + cucumber-wire (~> 0.0.1) + diff-lcs (>= 1.1.3) + gherkin (~> 4.0) + multi_json (>= 1.7.5, < 2.0) + multi_test (>= 0.1.2) + cucumber-core (1.5.0) + gherkin (~> 4.0) + cucumber-wire (0.0.1) + diff-lcs (1.3) + edn (1.1.1) + escape (0.0.4) + geocoder (1.4.4) + gherkin (4.1.3) + httpclient (2.8.3) + i18n (0.8.6) + json (1.8.6) + luffa (2.0.0) + awesome_print (~> 1.2) + json (~> 1.8) + retriable (>= 1.3.3.1, < 2.1) + thor (~> 0.19) + mime-types (2.99.3) + multi_json (1.12.1) + multi_test (0.1.2) + retriable (2.0.2) + rspec (3.6.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-core (3.6.0) + rspec-support (~> 3.6.0) + rspec-expectations (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-mocks (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-support (3.6.0) + rubyzip (1.2.1) + run_loop (2.4.1) + CFPropertyList (~> 2.2) + awesome_print (~> 1.2) + command_runner_ng (>= 0.0.2) + httpclient (>= 2.7.1, < 3.0) + i18n (>= 0.7.0, < 1.0) + json (~> 1.8) + thor (>= 0.18.1, < 1.0) + slowhandcuke (0.0.3) + cucumber + thor (0.19.4) + xamarin-test-cloud (2.1.2) + bundler (>= 1.3.0, < 2.0) + httpclient (>= 2.7.1, < 3.0) + json (~> 1.8) + mime-types (~> 2.99) + retriable (>= 1.3.3.1, < 2.1) + rubyzip (~> 1.1) + thor (>= 0.18.1, < 1.0) + +PLATFORMS + ruby + +DEPENDENCIES + calabash-android + calabash-cucumber + rspec + xamarin-test-cloud + +BUNDLED WITH + 1.14.6 diff --git a/PrebidMobile/IntegrationTests/features/base_test.feature b/PrebidMobile/IntegrationTests/features/base_test.feature index 2dce27e2a..7b4995e64 100644 --- a/PrebidMobile/IntegrationTests/features/base_test.feature +++ b/PrebidMobile/IntegrationTests/features/base_test.feature @@ -1,19 +1,36 @@ Feature: Base test -Scenario: Load DFP Interstitial Ad +Scenario: Load DFP Banner Ad Given I wait for the "MainActivity" screen to appear Then I press "DFP" - Then I press "Show Interstitial Example" - Then I press "loadInterstitial" - Then I wait for 5 seconds + Then I press "Show Banner Example" + Then I press "Refresh Banner" + Then I wait for 10 seconds Then I should see AppNexus creative - Then I press "Interstitial close button" -Scenario: Load DFP Banner Ad +#Scenario: Load DFP Interstitial Ad +#Given I wait for the "MainActivity" screen to appear +#Then I press "DFP" +#Then I press "Show Interstitial Example" +#Then I press "loadInterstitial" +#Then I wait for 5 seconds +#Then I should see AppNexus creative +#Then I press "Interstitial close button" + +Scenario: Load MoPub Banner Ad Given I wait for the "MainActivity" screen to appear - Then I press "DFP" + Then I press "MoPub" Then I press "Show Banner Example" Then I press "Refresh Banner" - Then I wait for 5 seconds - Then I should see AppNexus creative in PublisherAdView number 0 - Then I should see AppNexus creative in PublisherAdView number 1 + Then I wait for 10 seconds + Then I should see AppNexus creative in HTMLBannerWebView + +#Scenario: Load MoPub Interstitial Ad +#Given I wait for the "MainActivity" screen to appear +#Then I press "MoPub" +#Then I press "Show Interstitial Example" +#Then I press "loadInterstitial" +#Then I press "loadInterstitial" +#Then I wait for 5 seconds +#Then I should see AppNexus creative in MraidBridgeMraidWebView +#Then I press "Interstitial close button" diff --git a/PrebidMobile/IntegrationTests/features/step_definitions/calabash_steps.rb b/PrebidMobile/IntegrationTests/features/step_definitions/calabash_steps.rb index cb7508dbb..1902a6483 100644 --- a/PrebidMobile/IntegrationTests/features/step_definitions/calabash_steps.rb +++ b/PrebidMobile/IntegrationTests/features/step_definitions/calabash_steps.rb @@ -1,16 +1,35 @@ require 'calabash-android/calabash_steps' Then(/^I should see AppNexus creative$/) do - @query_results = query("o css:'*'") - unless @query_results[0]['html'].include?('mbpb.js') - raise "Mbpb.js not found, prebid creative was not served" + webview_class = backdoor "getDFPWebViewName" + names = webview_class.split('.') + len = names.length + short_name = names[len-1] + @query_results = query(short_name + " css:'body'") + unless @query_results[1]['html'].include?('pbm.js') + raise "Pbm.js not found, prebid creative was not served" end end Then(/^I should see AppNexus creative in PublisherAdView number (\d+)$/) do |arg1| - @query_results = query("o index:#{arg1} css:'*'") - unless @query_results[0]['html'].include?('mbpb.js') - raise "Mbpb.js not found, prebid creative was not served in number #{arg1} PublisherAdView" - end + webview_class = backdoor "getDFPWebViewName" + @query_results = query(webview_class + " index:#{arg1} css:'*'") + unless @query_results[0]['html'].include?('pbm.js') + raise "Pbm.js not found, prebid creative was not served in number #{arg1} PublisherAdView" + end +end + +Then(/^I should see AppNexus creative in HTMLBannerWebView$/) do + @query_results = query("HTMLBannerWebView css:'body'") + unless @query_results[1]['html'].include?('pbm.js') + raise "Pbm.js not found, prebid creative was not served" + end +end + +Then(/^I should see AppNexus creative in MraidBridgeMraidWebView$/) do + @query_results = query("MraidWebView css:'*'") + unless @query_results[0]['html'].include?('pbm.js') + raise "Pbm.js not found, prebid creative was not served" + end end diff --git a/PrebidMobile/IntegrationTests/run_tests_local.sh b/PrebidMobile/IntegrationTests/run_tests_local.sh index b3fbaf55e..e033533b7 100755 --- a/PrebidMobile/IntegrationTests/run_tests_local.sh +++ b/PrebidMobile/IntegrationTests/run_tests_local.sh @@ -7,9 +7,12 @@ echo -e "CALABASH BUILDLOG: $@" echoX "Build the apk." cd .. ./gradlew clean build -cp DemoApp/build/outputs/apk/DemoApp-release-unsigned.apk IntegrationTests/apk/DemoApp.apk +cp DemoApp/build/outputs/apk/DemoApp-debug.apk IntegrationTests/apk/DemoApp.apk cd IntegrationTests echoX "Run the tests." calabash-android resign apk/DemoApp.apk calabash-android run apk/DemoApp.apk + +# to debug your test if it fails, run calabash-android console apk/DemoApp.apk +# for more details see https://github.com/calabash/calabash-android/blob/master/documentation/ruby_api.md diff --git a/testprebid.sh b/testprebid.sh index 3d984d940..3e52805e8 100755 --- a/testprebid.sh +++ b/testprebid.sh @@ -1,5 +1,13 @@ #! /bin/bash - cd PrebidMobile ./gradlew clean test +./gradlew clean assembleDebug +mkdir -p IntegrationTests/apk && cp DemoApp/build/outputs/apk/DemoApp-debug.apk IntegrationTests/apk/DemoApp.apk + +cd IntegrationTests +bundle install + +bundle exec calabash-android resign apk/DemoApp.apk +bundle exec calabash-android build apk/DemoApp.apk +bundle exec test-cloud submit apk/DemoApp.apk 435c130f3f6ff5256d19a790c21dd653 --devices 2ae0b5a0 --series "master" --locale "en_US" --app-name "DemoApp" --user nhedley@appnexus.com