diff --git a/README.md b/README.md index 4ff5299..f8f07e9 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,11 @@ Assumptions: * You have AndroidStudios and Xcode installed. * You have Xcode command line tools installed. * You have npm & Appium installed. https://www.npmjs.com/package/appium - * You're running this on a Mac. (For iOS tests only.) + * You followed the Appium setup instructions http://appium.io/slate/en/1.5/?ruby#setup for android & iOS. + * You're running this on a Mac for iOS. For android, you can run on Windows and Linux with some tweaking. * You have Homebrew installed. http://brew.sh/ - * You have ideviceinstaller installed for iOS test. `brew install ideviceinstaller` + * You have ideviceinstaller installed for iOS tests. `brew install ideviceinstaller` + * You have enabled UI Automation in Settings > Developer for iOS. * You have android emulators installed or USB connected devices with USB Debug enabled. To set up: @@ -38,7 +40,8 @@ To set up: ## Running Specs -* Start emulators or connect devices! +* Start android emulators or connect devices! +* iOS is setup to only run on real devices. This is due to Apple's limitation of allowing only one running emulator per machine. To run specs single threaded: @@ -63,9 +66,9 @@ To run specs on SauceLabs: `export SAUCE_ACCESS_KEY=` - `rake android/ios[single,sauce]` << "Will run tests tagged with :sauce single threaded" + `rake android/ios[single,sauce]` <- "Will run tests tagged with :sauce single threaded" - `rake android/ios[dist,sauce]` << "Will run tests tagged with :sauce distributed" + `rake android/ios[dist,sauce]` <- "Will run tests tagged with :sauce distributed" Generate Allure report: (Displays test results, hub log, appium log, screenshots and video) @@ -87,8 +90,16 @@ Generate Allure report: (Displays test results, hub log, appium log, screenshots * Make sure you get "SUCCESS: Validated pairing with device " * You should now be able to install the app manually. + `ideviceinstaller -u -i ./appium-mobile-grid/ios/TestApp/build/Release-iphoneos/TestApp.app.zip` + + * Build the app with xcodebuild + + `cd ios/TestApp` + + `xcodebuild -sdk iphoneos` <- This will place a new binary in appium-mobile-grid/ios/TestApp/build/Release-iphoneos + `ideviceinstaller -u -i ./appium-mobile-grid/ios/TestApp/build/Release-iphoneos/TestApp.app` -Disclaimer: +## Disclaimer: * This example was built quickly, so the code is not in the optimal state of dryness. * No page objects were used. The tests are soley for example purposes. diff --git a/Rakefile b/Rakefile index 335744d..aeefd36 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,13 @@ end desc 'Running iOS tests!' task :ios, :type, :tag do |t, args| - task_setup ios_app, t.to_s, args + + # if args[:tag].include? "sauce" + # app = ios_app_sauce + # else + app = ios_app + #end + task_setup app, t.to_s, args end def task_setup app, platform, args @@ -17,8 +23,7 @@ def task_setup app, platform, args abort end - system "mkdir output >> /dev/null 2>&1" - clear_old_test_data + setup_output_dir ENV["BASE_DIR"], ENV["APP_PATH"] = Dir.pwd, app @@ -33,13 +38,8 @@ def task_setup app, platform, args ENV["SERVER_URL"] = "http://localhost:4444/wd/hub" #Change this to your hub url if different. end elsif tag.include? "sauce" - if platform == "ios" - puts "Sorry, this example is not setup to run iOS on sauce labs. Android only...\n" - return - else - ENV["ENV"], ENV["SERVER_URL"] = "sauce","http://#{ENV['SAUCE_USERNAME']}:#{ENV['SAUCE_ACCESS_KEY']}@ondemand.saucelabs.com:80/wd/hub" - upload_app_to_sauce app - end + ENV["ENV"], ENV["SERVER_URL"] = "sauce","http://#{ENV['SAUCE_USERNAME']}:#{ENV['SAUCE_ACCESS_KEY']}@ondemand.saucelabs.com:80/wd/hub" + upload_app_to_sauce app end Dir.chdir platform @@ -62,6 +62,10 @@ def ios_app "#{Dir.pwd}/ios/TestApp/build/Release-iphoneos/TestApp.app.zip" end +def ios_app_sauce + "#{Dir.pwd}/ios/TestApp/build/Release-iphonesimulator/TestApp.app.zip" +end + def upload_app_to_sauce app require 'sauce_whisk' storage = SauceWhisk::Storage.new @@ -70,7 +74,8 @@ def upload_app_to_sauce app ENV["APP_PATH"] = "sauce-storage:#{File.basename(app)}" end -def clear_old_test_data +def setup_output_dir + system "mkdir output >> /dev/null 2>&1" `/bin/rm -rf ./output/allure/* >> /dev/null 2>&1` `rm ./output/* >> /dev/null 2>&1` end \ No newline at end of file diff --git a/android/spec/add_note_spec.rb b/android/spec/add_note_spec.rb index db1f010..88c9a8b 100644 --- a/android/spec/add_note_spec.rb +++ b/android/spec/add_note_spec.rb @@ -13,6 +13,6 @@ find_element(:id, 'com.example.android.notepad:id/note').send_keys note find_element(:id, 'com.example.android.notepad:id/menu_save').click wait_true { find_element(:id, "android:id/action_bar_title").text.eql? "Notes" } - expect(find_element(:id, 'android:id/text1').text).to eq "fail_on_purpose" #note + expect(find_element(:id, 'android:id/text1').text).to eq "FAIL ON PURPOSE!!!" end end \ No newline at end of file diff --git a/android/spec/spec_helper.rb b/android/spec/spec_helper.rb index 640a050..70e26b2 100755 --- a/android/spec/spec_helper.rb +++ b/android/spec/spec_helper.rb @@ -22,7 +22,7 @@ helper.stop_logcat helper.stop_video_record ENV["UDID"] end - update_sauce_status @driver.session_id, e.exception.nil? + update_sauce_status_get_assets @driver.session_id, e.exception.nil? unless e.exception.nil? attach_report_files e end diff --git a/android/start_emulators.rb b/android/start_emulators.rb index 29f988b..e54d05f 100644 --- a/android/start_emulators.rb +++ b/android/start_emulators.rb @@ -2,5 +2,5 @@ emulators = (`emulator -list-avds`).split("\n") Parallel.map(emulators, :in_threads=> emulators.size) do |emulator| - spawn("emulator -avd #{emulator} -scale 128dpi -no-boot-anim -cpu-delay 0 -no-audio -accel on &", :out=> "/dev/null") + spawn("emulator -avd #{emulator} -scale 100dpi -no-boot-anim -cpu-delay 0 -no-audio -accel on &", :out=> "/dev/null") end \ No newline at end of file diff --git a/common/dowload_sauce_assets.rb b/common/dowload_sauce_assets.rb new file mode 100644 index 0000000..0490299 --- /dev/null +++ b/common/dowload_sauce_assets.rb @@ -0,0 +1,20 @@ +require 'saucewhisk' +require 'parallel' + +def download_sauce_assets job_id, name = "sauce" + job = SauceWhisk::Jobs + until !job.fetch(job_id).screenshot_urls.nil? + puts "Waiting for sauce to mark job as completed..."; sleep 5 + end + screenshot = job.fetch(job_id).screenshot_urls.last + assets = [{file: "selenium-server.log", name: "appium-#{name}.log"}, {file: "video.flv", name: "video-#{name}.flv"}, {file: screenshot, name: "screenshot-#{name}.png"}] + Parallel.each(assets, :in_threads=> assets.size) do |asset| + %x(curl -s -u #{ENV["SAUCE_USERNAME"]}:#{ENV["SAUCE_ACCESS_KEY"]} https://saucelabs.com/rest/#{ENV["SAUCE_USERNAME"]}/jobs/#{job_id}/results/#{asset[:file]} > ../output/#{asset[:name]}) + end +end + +if ARGV[0].nil? + puts "Please supply a sauce labs job id...\ne.g. download_sauce_assets e6dc361349aa85sdf27acdf38f7d" +else + download_sauce_assets ARGV[0] +end \ No newline at end of file diff --git a/common/methods.rb b/common/methods.rb index 7743a31..43f0fdb 100644 --- a/common/methods.rb +++ b/common/methods.rb @@ -3,7 +3,7 @@ Bundler.require(:test) include Faker -def update_sauce_status job_id, status +def update_sauce_status_get_assets job_id, status return unless ENV["ENV"] == "sauce" job = SauceWhisk::Jobs job.change_status job_id, status @@ -30,11 +30,11 @@ def initialize_appium_and_methods platform device = get_device_data caps = Appium.load_appium_txt file: File.join(File.dirname(__FILE__), "../#{platform}/appium.txt") caps[:caps][:udid] = device.fetch("udid", nil) - caps[:caps][:platformVersion] = device.fetch("os", nil) - caps[:caps][:deviceName] = device.fetch("name", platform) + caps[:caps][:platformVersion] = device.fetch("os", caps[:caps][:platformVersion]) + caps[:caps][:deviceName] = device.fetch("name", caps[:caps][:deviceName]) caps[:caps][:app] = ENV["APP_PATH"] caps[:appium_lib][:server_url] = ENV["SERVER_URL"] - caps[:caps][:name] = self.class.metadata[:full_description] #for sauce labs test description + caps[:caps][:name] = self.class.metadata[:full_description].strip #for sauce labs test description @driver = Appium::Driver.new(caps).start_driver Appium.promote_appium_methods Object Appium.promote_appium_methods RSpec::Core::ExampleGroup diff --git a/ios/TestApp/build/Release-iphoneos/TestApp.app/GestureTestViewController.nib/objects.nib b/ios/TestApp/build/Release-iphoneos/TestApp.app/GestureTestViewController.nib/objects.nib index 641c577..9959433 100644 Binary files a/ios/TestApp/build/Release-iphoneos/TestApp.app/GestureTestViewController.nib/objects.nib and b/ios/TestApp/build/Release-iphoneos/TestApp.app/GestureTestViewController.nib/objects.nib differ diff --git a/ios/TestApp/build/Release-iphoneos/TestApp.app/GestureTestViewController.nib/runtime.nib b/ios/TestApp/build/Release-iphoneos/TestApp.app/GestureTestViewController.nib/runtime.nib index ca3fa19..026088f 100644 Binary files a/ios/TestApp/build/Release-iphoneos/TestApp.app/GestureTestViewController.nib/runtime.nib and b/ios/TestApp/build/Release-iphoneos/TestApp.app/GestureTestViewController.nib/runtime.nib differ diff --git a/ios/TestApp/build/Release-iphoneos/TestApp.app/TestApp b/ios/TestApp/build/Release-iphoneos/TestApp.app/TestApp index d37630c..bbcd196 100755 Binary files a/ios/TestApp/build/Release-iphoneos/TestApp.app/TestApp and b/ios/TestApp/build/Release-iphoneos/TestApp.app/TestApp differ diff --git a/ios/TestApp/build/Release-iphoneos/TestApp.app/_CodeSignature/CodeResources b/ios/TestApp/build/Release-iphoneos/TestApp.app/_CodeSignature/CodeResources index 9e57616..59b9f3e 100644 --- a/ios/TestApp/build/Release-iphoneos/TestApp.app/_CodeSignature/CodeResources +++ b/ios/TestApp/build/Release-iphoneos/TestApp.app/_CodeSignature/CodeResources @@ -10,11 +10,11 @@ GestureTestViewController.nib/objects.nib - PikijxbM4Jpu1fDDKl1j7ur5o5E= + 7LDB0Duzk739rHCpsPaoq8iTZFY= GestureTestViewController.nib/runtime.nib - AvnqRGhivJ+1JwfzmMCWLCCW8VA= + bGcbxpseenEib767nqVmOaZL1XU= Info.plist @@ -50,7 +50,7 @@ hash - 2Y9SRA8/hRtumxSEByu1kxZjHvQ= + 6q8863bi9fHijEWqYFnBSbBTFeA= optional @@ -59,7 +59,7 @@ hash - STkdYEXfV6DYu1PP8uf+wjLoUZU= + SAjuIeWeTGDDu4G8qfajqzipxhg= optional @@ -73,11 +73,11 @@ GestureTestViewController.nib/objects.nib - PikijxbM4Jpu1fDDKl1j7ur5o5E= + 7LDB0Duzk739rHCpsPaoq8iTZFY= GestureTestViewController.nib/runtime.nib - AvnqRGhivJ+1JwfzmMCWLCCW8VA= + bGcbxpseenEib767nqVmOaZL1XU= embedded.mobileprovision @@ -105,7 +105,7 @@ hash - 2Y9SRA8/hRtumxSEByu1kxZjHvQ= + 6q8863bi9fHijEWqYFnBSbBTFeA= optional @@ -114,7 +114,7 @@ hash - STkdYEXfV6DYu1PP8uf+wjLoUZU= + SAjuIeWeTGDDu4G8qfajqzipxhg= optional diff --git a/ios/TestApp/build/Release-iphoneos/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects.nib b/ios/TestApp/build/Release-iphoneos/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects.nib index 525f72b..b46074a 100644 Binary files a/ios/TestApp/build/Release-iphoneos/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects.nib and b/ios/TestApp/build/Release-iphoneos/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects.nib differ diff --git a/ios/TestApp/build/Release-iphoneos/TestApp.app/en.lproj/MyViewControllerViewController.nib/runtime.nib b/ios/TestApp/build/Release-iphoneos/TestApp.app/en.lproj/MyViewControllerViewController.nib/runtime.nib index 7d9e5f6..88e90cd 100644 Binary files a/ios/TestApp/build/Release-iphoneos/TestApp.app/en.lproj/MyViewControllerViewController.nib/runtime.nib and b/ios/TestApp/build/Release-iphoneos/TestApp.app/en.lproj/MyViewControllerViewController.nib/runtime.nib differ diff --git a/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/Objects-normal/armv7/TestApp_dependency_info.dat b/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/Objects-normal/armv7/TestApp_dependency_info.dat index 98519ef..6fb813d 100644 Binary files a/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/Objects-normal/armv7/TestApp_dependency_info.dat and b/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/Objects-normal/armv7/TestApp_dependency_info.dat differ diff --git a/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/dgph b/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/dgph index 4da04f4..ddd496e 100644 Binary files a/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/dgph and b/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/dgph differ diff --git a/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/dgph~ b/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/dgph~ index 2be8ae3..4da04f4 100644 Binary files a/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/dgph~ and b/ios/TestApp/build/TestApp.build/Release-iphoneos/TestApp.build/dgph~ differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app.zip b/ios/TestApp/build/release-iphonesimulator/TestApp.app.zip new file mode 100644 index 0000000..494b821 Binary files /dev/null and b/ios/TestApp/build/release-iphonesimulator/TestApp.app.zip differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/GestureTestViewController.nib/objects-8.0+.nib b/ios/TestApp/build/release-iphonesimulator/TestApp.app/GestureTestViewController.nib/objects-8.0+.nib deleted file mode 100644 index f6249fb..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/GestureTestViewController.nib/objects-8.0+.nib and /dev/null differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/GestureTestViewController.nib/objects.nib b/ios/TestApp/build/release-iphonesimulator/TestApp.app/GestureTestViewController.nib/objects.nib deleted file mode 100644 index e14f21e..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/GestureTestViewController.nib/objects.nib and /dev/null differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/GestureTestViewController.nib/runtime.nib b/ios/TestApp/build/release-iphonesimulator/TestApp.app/GestureTestViewController.nib/runtime.nib deleted file mode 100644 index 96afed0..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/GestureTestViewController.nib/runtime.nib and /dev/null differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/Info.plist b/ios/TestApp/build/release-iphonesimulator/TestApp.app/Info.plist deleted file mode 100644 index 1b0cc18..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/Info.plist and /dev/null differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/PkgInfo b/ios/TestApp/build/release-iphonesimulator/TestApp.app/PkgInfo deleted file mode 100644 index bd04210..0000000 --- a/ios/TestApp/build/release-iphonesimulator/TestApp.app/PkgInfo +++ /dev/null @@ -1 +0,0 @@ -APPL???? \ No newline at end of file diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/TestApp b/ios/TestApp/build/release-iphonesimulator/TestApp.app/TestApp deleted file mode 100755 index 5453507..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/TestApp and /dev/null differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/InfoPlist.strings b/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/InfoPlist.strings deleted file mode 100644 index 3967e06..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/InfoPlist.strings and /dev/null differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/Localizable.strings b/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/Localizable.strings deleted file mode 100644 index ed5825b..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/Localizable.strings and /dev/null differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects-8.0+.nib b/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects-8.0+.nib deleted file mode 100644 index 596cf7e..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects-8.0+.nib and /dev/null differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects.nib b/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects.nib deleted file mode 100644 index a84929e..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/MyViewControllerViewController.nib/objects.nib and /dev/null differ diff --git a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/MyViewControllerViewController.nib/runtime.nib b/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/MyViewControllerViewController.nib/runtime.nib deleted file mode 100644 index b76ac00..0000000 Binary files a/ios/TestApp/build/release-iphonesimulator/TestApp.app/en.lproj/MyViewControllerViewController.nib/runtime.nib and /dev/null differ diff --git a/ios/appium.txt b/ios/appium.txt index 75a8fc2..af56a17 100644 --- a/ios/appium.txt +++ b/ios/appium.txt @@ -1,6 +1,8 @@ [caps] appium-version = "1.4.16" platformName = "iOS" +platformVersion = "9.2" +deviceName = "iPhone Simulator" [appium_lib] wait = 30 \ No newline at end of file diff --git a/ios/spec/alert_spec.rb b/ios/spec/alert_spec.rb index fd3ff7d..d069f97 100644 --- a/ios/spec/alert_spec.rb +++ b/ios/spec/alert_spec.rb @@ -2,7 +2,7 @@ describe "Validate Alert Popups #{ENV["UDID"]}" do - it 'Alert popup text' do + it 'Alert popup text', :sauce do find_element(:id, "show alert").click expect(texts.first.text).to eq "Cool title" expect(texts.last.text).to eq "FAIL ON PURPOSE!!!" diff --git a/ios/spec/features_spec.rb b/ios/spec/features_spec.rb index 3ef9a8e..841afa1 100644 --- a/ios/spec/features_spec.rb +++ b/ios/spec/features_spec.rb @@ -12,7 +12,7 @@ it 'Slide Slidder' do slider = find_element(:class, "UIASlider") - Appium::TouchAction.new.press(element: slider, x: 60, y: 3).move_to(element: slider, x: 130, y: 3).release.perform + Appium::TouchAction.new.press(element: slider, x: 60, y: 3).move_to(element: slider, x: 150, y: 3).release.perform expect(slider.value).to eq "100%" end end \ No newline at end of file diff --git a/ios/spec/spec_helper.rb b/ios/spec/spec_helper.rb index dc5519d..0b006e6 100755 --- a/ios/spec/spec_helper.rb +++ b/ios/spec/spec_helper.rb @@ -11,6 +11,7 @@ end config.after :each do |e| + update_sauce_status @driver.session_id, e.exception.nil? unless e.exception.nil? attach_report_files e end