Skip to content

Commit 08c826f

Browse files
authored
for test code: add taking screens if tests failed (#30)
* add taling screens if tests failed * fix rubocop and save reports
1 parent f14c924 commit 08c826f

11 files changed

+67
-10
lines changed

test/functional/android/android/device_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
66
module Android
7-
class DeviceTest < Minitest::Test
7+
class DeviceTest < AppiumLibCoreTest::Function::TestCase
88
def setup
99
@@core ||= ::Appium::Core.for(self, Caps::ANDROID_OPS)
1010
@@driver ||= @@core.start_driver
@@ -13,6 +13,10 @@ def setup
1313
app_activity: '.ApiDemos'
1414
end
1515

16+
def teardown
17+
save_reports(@@driver)
18+
end
19+
1620
def test_window_size
1721
size = @@driver.window_size
1822
assert size.width

test/functional/android/android/search_context_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
66
module Ios
7-
class SearchContextTest < Minitest::Test
7+
class SearchContextTest < AppiumLibCoreTest::Function::TestCase
88
def setup
99
@@core ||= ::Appium::Core.for(self, Caps::ANDROID_OPS)
1010
@@driver ||= @@core.start_driver
1111
end
1212

13+
def teardown
14+
save_reports(@@driver)
15+
end
16+
1317
def test_uiautomation
1418
e = @@driver.find_elements :uiautomator, 'new UiSelector().clickable(true)'
1519

test/functional/android/driver_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
# $ rake test:func:android TEST=test/functional/android/driver_test.rb
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
6-
class DriverTest < Minitest::Test
6+
class DriverTest < AppiumLibCoreTest::Function::TestCase
77
def setup
88
@@core ||= ::Appium::Core.for(self, Caps::ANDROID_OPS)
99
@@driver ||= @@core.start_driver
1010
end
1111

12+
def teardown
13+
save_reports(@@driver)
14+
end
15+
1216
def test_appium_server_version
1317
v = @@core.appium_server_version
1418

test/functional/android/patch_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# $ rake test:func:android TEST=test/functional/android/patch_test.rb
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
6-
class PathTest < Minitest::Test
6+
class PathTest < AppiumLibCoreTest::Function::TestCase
77
def setup
88
@@core ||= ::Appium::Core.for(self, Caps::ANDROID_OPS)
99
@@driver ||= @@core.start_driver
@@ -12,6 +12,10 @@ def setup
1212
app_activity: '.ApiDemos'
1313
end
1414

15+
def teardown
16+
save_reports(@@driver)
17+
end
18+
1519
def test_value
1620
skip "Android doesn't support"
1721
e = @@core.wait { @@driver.find_element :accessibility_id, 'App' }

test/functional/android/webdriver/device_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
66
module WebDriver
7-
class DeviceTest < Minitest::Test
7+
class DeviceTest < AppiumLibCoreTest::Function::TestCase
88
def setup
99
@@core ||= ::Appium::Core.for(self, Caps::ANDROID_OPS)
1010
@@driver ||= @@core.start_driver
@@ -13,6 +13,10 @@ def setup
1313
app_activity: '.ApiDemos'
1414
end
1515

16+
def teardown
17+
save_reports(@@driver)
18+
end
19+
1620
def test_capabilities
1721
assert @@driver.capabilities
1822
end

test/functional/ios/driver_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
# $ rake test:func:ios TEST=test/functional/ios/driver_test.rb
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
6-
class DriverTest < Minitest::Test
6+
class DriverTest < AppiumLibCoreTest::Function::TestCase
77
def setup
88
@@core ||= ::Appium::Core.for(self, Caps::IOS_OPS)
99
@@driver ||= @@core.start_driver
1010
end
1111

12+
def teardown
13+
save_reports(@@driver)
14+
end
15+
1216
def test_appium_server_version
1317
v = @@core.appium_server_version
1418

test/functional/ios/ios/device_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
66
module Ios
7-
class DeviceTest < Minitest::Test
7+
class DeviceTest < AppiumLibCoreTest::Function::TestCase
88
def setup
99
@@core ||= ::Appium::Core.for(self, Caps::IOS_OPS)
1010
@@driver ||= @@core.start_driver
1111
end
1212

13+
def teardown
14+
save_reports(@@driver)
15+
end
16+
1317
def test_window_size
1418
size = @@driver.window_size
1519
assert size.width

test/functional/ios/ios/search_context_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
66
module Ios
7-
class SearchContextTest < Minitest::Test
7+
class SearchContextTest < AppiumLibCoreTest::Function::TestCase
88
def setup
99
@@core ||= ::Appium::Core.for(self, Caps::IOS_OPS)
1010
@@driver ||= @@core.start_driver
1111
end
1212

13+
def teardown
14+
save_reports(@@driver)
15+
end
16+
1317
def test_uiautomation
1418
if @@core.automation_name != :xcuitest
1519
e = @@driver.find_element :predicate, 'wdName == "Buttons"'

test/functional/ios/patch_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
# $ rake test:func:ios TEST=test/functional/ios/patch_test.rb
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
6-
class PathTest < Minitest::Test
6+
class PathTest < AppiumLibCoreTest::Function::TestCase
77
def setup
88
@@core ||= ::Appium::Core.for(self, Caps::IOS_OPS)
99
@@driver ||= @@core.start_driver
1010
end
1111

12+
def teardown
13+
save_reports(@@driver)
14+
end
15+
1216
def test_value
1317
e = @@core.wait { @@driver.find_element :accessibility_id, 'Buttons' }
1418

test/functional/ios/webdriver/device_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
66
module WebDriver
7-
class DeviceTest < Minitest::Test
7+
class DeviceTest < AppiumLibCoreTest::Function::TestCase
88
def setup
99
@@core ||= ::Appium::Core.for(self, Caps::IOS_OPS)
1010
@@driver ||= @@core.start_driver
1111
end
1212

13+
def teardown
14+
save_reports(@@driver)
15+
end
16+
1317
def test_capabilities
1418
assert @@driver.capabilities
1519
end

test/test_helper.rb

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88

99
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
1010

11+
ROOT_REPORT_PATH = "#{Dir.pwd}/test/report/".freeze
12+
Dir.mkdir(ROOT_REPORT_PATH) unless Dir.exist? ROOT_REPORT_PATH
13+
14+
class AppiumLibCoreTest
15+
module Function
16+
class TestCase < Minitest::Test
17+
def save_reports(driver)
18+
return if passed?
19+
20+
path = "#{ROOT_REPORT_PATH}#{self.class.name.gsub('::', '_')}-#{name}-error"
21+
File.write "#{path}.xml", driver.page_source
22+
driver.save_screenshot "#{path}.png"
23+
end
24+
end
25+
end
26+
end
27+
1128
class AppiumLibCoreTest
1229
module Caps
1330
# Require a simulator which OS version is 10.3, for example.

0 commit comments

Comments
 (0)