Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
isonic1 committed Feb 25, 2016
1 parent 5b500a4 commit 978d6d2
Show file tree
Hide file tree
Showing 32 changed files with 73 additions and 35 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand 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:

Expand All @@ -63,9 +66,9 @@ To run specs on SauceLabs:

`export SAUCE_ACCESS_KEY=<your 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)

Expand All @@ -87,8 +90,16 @@ Generate Allure report: (Displays test results, hub log, appium log, screenshots
* Make sure you get "SUCCESS: Validated pairing with device <udid>"
* You should now be able to install the app manually.

`ideviceinstaller -u <udid> -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 <udid> -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.
27 changes: 16 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion android/spec/add_note_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion android/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion android/start_emulators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions common/dowload_sauce_assets.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions common/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified ios/TestApp/build/Release-iphoneos/TestApp.app/TestApp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
</data>
<key>GestureTestViewController.nib/objects.nib</key>
<data>
PikijxbM4Jpu1fDDKl1j7ur5o5E=
7LDB0Duzk739rHCpsPaoq8iTZFY=
</data>
<key>GestureTestViewController.nib/runtime.nib</key>
<data>
AvnqRGhivJ+1JwfzmMCWLCCW8VA=
bGcbxpseenEib767nqVmOaZL1XU=
</data>
<key>Info.plist</key>
<data>
Expand Down Expand Up @@ -50,7 +50,7 @@
<dict>
<key>hash</key>
<data>
2Y9SRA8/hRtumxSEByu1kxZjHvQ=
6q8863bi9fHijEWqYFnBSbBTFeA=
</data>
<key>optional</key>
<true/>
Expand All @@ -59,7 +59,7 @@
<dict>
<key>hash</key>
<data>
STkdYEXfV6DYu1PP8uf+wjLoUZU=
SAjuIeWeTGDDu4G8qfajqzipxhg=
</data>
<key>optional</key>
<true/>
Expand All @@ -73,11 +73,11 @@
</data>
<key>GestureTestViewController.nib/objects.nib</key>
<data>
PikijxbM4Jpu1fDDKl1j7ur5o5E=
7LDB0Duzk739rHCpsPaoq8iTZFY=
</data>
<key>GestureTestViewController.nib/runtime.nib</key>
<data>
AvnqRGhivJ+1JwfzmMCWLCCW8VA=
bGcbxpseenEib767nqVmOaZL1XU=
</data>
<key>embedded.mobileprovision</key>
<data>
Expand Down Expand Up @@ -105,7 +105,7 @@
<dict>
<key>hash</key>
<data>
2Y9SRA8/hRtumxSEByu1kxZjHvQ=
6q8863bi9fHijEWqYFnBSbBTFeA=
</data>
<key>optional</key>
<true/>
Expand All @@ -114,7 +114,7 @@
<dict>
<key>hash</key>
<data>
STkdYEXfV6DYu1PP8uf+wjLoUZU=
SAjuIeWeTGDDu4G8qfajqzipxhg=
</data>
<key>optional</key>
<true/>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions ios/appium.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[caps]
appium-version = "1.4.16"
platformName = "iOS"
platformVersion = "9.2"
deviceName = "iPhone Simulator"

[appium_lib]
wait = 30
2 changes: 1 addition & 1 deletion ios/spec/alert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!"
Expand Down
2 changes: 1 addition & 1 deletion ios/spec/features_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions ios/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 978d6d2

Please sign in to comment.