Skip to content

Commit a3db411

Browse files
authoredFeb 5, 2024
test: add tests for future (#521)
1 parent 3d5a6de commit a3db411

File tree

4 files changed

+83
-17
lines changed

4 files changed

+83
-17
lines changed
 

‎test/functional/android/android/search_context_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ def test_uiautomator
3434
e = @driver.find_element :uiautomator, 'new UiSelector().clickable(true)'
3535
assert e
3636
assert_equal "Access'ibility", e.tag_name
37+
assert_equal ::Appium::Core::Element, e.class
3738
end
3839

3940
def test_viewtag
4041
skip 'UiAutomator2 does not support viewtag' if @@core.automation_name != :espresso
4142

4243
e = @driver.find_elements :viewtag, 'example'
4344
assert_equal 0, e.size
45+
assert_equal ::Appium::Core::Element, e.class
4446
end
4547

4648
def test_datamatcher
@@ -49,6 +51,7 @@ def test_datamatcher
4951
e = @driver.find_elements :data_matcher, { name: 'hasEntry', args: %w(title Animation) }.to_json
5052
assert_equal 1, e.size
5153
assert_equal 'Animation', e.first.tag_name
54+
assert_equal ::Appium::Core::Element, e.class
5255

5356
e.first.click
5457
@driver.find_element :accessibility_id, 'Cloning' # no error
@@ -94,6 +97,7 @@ def test_viewmatcher
9497
class: 'org.hamcrest.Matchers'
9598
}.to_json
9699
assert_equal "Access'ibility", e.text
100+
assert_equal ::Appium::Core::Element, e.class
97101
end
98102
end
99103
end

‎test/functional/ios/ios/search_context_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def teardown
3131
def test_predicate
3232
e = @@driver.find_element :predicate, 'wdName == "Buttons"'
3333
assert_equal 'Buttons', e.name
34+
assert_equal ::Appium::Core::Element, e.class
3435
end
3536

3637
def test_class_chain
3738
e = @@driver.find_element :class_chain, "**/XCUIElementTypeWindow[$name == 'Buttons'$]"
3839
assert_equal 'XCUIElementTypeWindow', e.tag_name
40+
assert_equal ::Appium::Core::Element, e.class
3941
end
4042
end
4143
end

‎test/unit/driver_test.rb

+72-12
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def test_default_wait
8484
end
8585

8686
def test_default_timeout_for_http_client
87-
@driver ||= android_mock_create_session
87+
driver = android_mock_create_session
8888

8989
assert_equal 999_999, @core.http_client.open_timeout
9090
assert_equal 999_999, @core.http_client.read_timeout
91-
uri = @driver.send(:bridge).http.send(:server_url)
91+
uri = driver.send(:bridge).http.send(:server_url)
9292
assert @core.direct_connect
9393
assert_equal 'http', uri.scheme
9494
assert_equal '127.0.0.1', uri.host
@@ -623,45 +623,105 @@ def test_listener_with_custom_listener_elements
623623
stub_request(:post, "#{SESSION}/element")
624624
.with(body: { using: 'id', value: 'example' }.to_json)
625625
.to_return(headers: HEADER, status: 200, body: {
626-
value: { ELEMENT: 'element_id_parent' }, sessionId: SESSION, status: 0
626+
value: { ::Appium::Core::Element::ELEMENT_KEY => 'element_id_parent' }, sessionId: SESSION, status: 0
627627
}.to_json)
628628
el = driver.find_element id: 'example'
629629
assert_requested :post, "#{SESSION}/element", times: 1
630-
assert_equal el.class.name, 'Appium::Core::Element'
630+
assert_equal ::Appium::Core::Element, el.class
631631

632632
# No W3C, but can call via '::Appium::Core::Element'
633633
stub_request(:get, "#{SESSION}/element/element_id_parent/displayed")
634634
.to_return(headers: HEADER, status: 200, body: { value: {} }.to_json)
635635
el.displayed?
636636
assert_requested :get, "#{SESSION}/element/element_id_parent/displayed", times: 1
637-
assert_equal el.class.name, 'Appium::Core::Element'
637+
assert_equal ::Appium::Core::Element, el.class
638638

639639
stub_request(:post, "#{SESSION}/element/element_id_parent/element")
640640
.with(body: { using: 'id', value: 'example2' }.to_json)
641641
.to_return(headers: HEADER, status: 200, body: {
642-
value: { ELEMENT: 'element_id_children' }, sessionId: SESSION, status: 0
642+
value: { ::Appium::Core::Element::ELEMENT_KEY => 'element_id_children' }, sessionId: SESSION, status: 0
643643
}.to_json)
644644
c_el = el.find_element id: 'example2'
645645
assert_requested :post, "#{SESSION}/element/element_id_parent/element", times: 1
646-
assert_equal c_el.class.name, 'Appium::Core::Element'
646+
assert_equal ::Appium::Core::Element, c_el.class
647647

648648
# elements
649649
stub_request(:post, "#{SESSION}/elements")
650650
.with(body: { using: 'id', value: 'example' }.to_json)
651651
.to_return(headers: HEADER, status: 200, body: {
652-
value: [{ ELEMENT: 'element_id_parent' }], sessionId: SESSION, status: 0
652+
value: [{ ::Appium::Core::Element::ELEMENT_KEY => 'element_id_parent' }], sessionId: SESSION, status: 0
653653
}.to_json)
654654
els = driver.find_elements id: 'example'
655+
assert_requested :post, "#{SESSION}/elements", times: 1
656+
assert_equal ::Appium::Core::Element, els.first.class
657+
658+
stub_request(:post, "#{SESSION}/element/element_id_parent/elements")
659+
.with(body: { using: 'id', value: 'example2' }.to_json)
660+
.to_return(headers: HEADER, status: 200, body: {
661+
value: [{ ::Appium::Core::Element::ELEMENT_KEY => 'element_id_children' }],
662+
sessionId: SESSION, status: 0
663+
}.to_json)
664+
c_el = els.first.find_elements id: 'example2'
665+
assert_requested :post, "#{SESSION}/element/element_id_parent/elements", times: 1
666+
assert_equal ::Appium::Core::Element, c_el.first.class
667+
end
668+
669+
def test_elements
670+
driver = android_mock_create_session
671+
672+
# element
673+
stub_request(:post, "#{SESSION}/element")
674+
.with(body: { using: 'id', value: 'example' }.to_json)
675+
.to_return(headers: HEADER, status: 200, body: {
676+
value: { ::Appium::Core::Element::ELEMENT_KEY => 'element_id_parent' }, sessionId: SESSION, status: 0
677+
}.to_json)
678+
el = driver.find_element id: 'example'
655679
assert_requested :post, "#{SESSION}/element", times: 1
656-
assert_equal els.first.class.name, 'Appium::Core::Element'
680+
assert_equal ::Appium::Core::Element, el.class
681+
682+
# No W3C, but can call via '::Appium::Core::Element'
683+
stub_request(:get, "#{SESSION}/element/element_id_parent/displayed")
684+
.to_return(headers: HEADER, status: 200, body: { value: {} }.to_json)
685+
el.displayed?
686+
assert_requested :get, "#{SESSION}/element/element_id_parent/displayed", times: 1
687+
assert_equal ::Appium::Core::Element, el.class
688+
689+
stub_request(:post, "#{SESSION}/element/element_id_parent/element")
690+
.with(body: { using: 'id', value: 'example2' }.to_json)
691+
.to_return(headers: HEADER, status: 200, body: {
692+
value: { ::Appium::Core::Element::ELEMENT_KEY => 'element_id_children' }, sessionId: SESSION, status: 0
693+
}.to_json)
694+
c_el = el.find_element id: 'example2'
695+
assert_requested :post, "#{SESSION}/element/element_id_parent/element", times: 1
696+
assert_equal ::Appium::Core::Element, c_el.class
697+
698+
# elements
699+
stub_request(:post, "#{SESSION}/elements")
700+
.with(body: { using: 'id', value: 'example' }.to_json)
701+
.to_return(headers: HEADER, status: 200, body: {
702+
value: [{ ::Appium::Core::Element::ELEMENT_KEY => 'element_id_parent' }], sessionId: SESSION, status: 0
703+
}.to_json)
704+
els = driver.find_elements id: 'example'
705+
assert_requested :post, "#{SESSION}/elements", times: 1
706+
assert_equal ::Appium::Core::Element, els.first.class
657707

658708
stub_request(:post, "#{SESSION}/element/element_id_parent/elements")
659709
.with(body: { using: 'id', value: 'example2' }.to_json)
660-
.to_return(headers: HEADER, status: 200, body: { value: [{ ELEMENT: 'element_id_children' }],
661-
sessionId: SESSION, status: 0 }.to_json)
710+
.to_return(headers: HEADER, status: 200, body: {
711+
value: [{ ::Appium::Core::Element::ELEMENT_KEY => 'element_id_children' }],
712+
sessionId: SESSION, status: 0
713+
}.to_json)
662714
c_el = els.first.find_elements id: 'example2'
663715
assert_requested :post, "#{SESSION}/element/element_id_parent/elements", times: 1
664-
assert_equal c_el.first.class.name, 'Appium::Core::Element'
716+
assert_equal ::Appium::Core::Element, c_el.first.class
717+
end
718+
719+
def test_convert_element
720+
driver = android_mock_create_session
721+
response = { 'element-6066-11e4-a52e-4f735466cecf' => 'test-element-id', 'ELEMENT' => 'test-element-id' }
722+
e = driver.convert_to_element response
723+
assert_equal 'test-element-id', e.id
724+
assert_equal ::Appium::Core::Element, e.class
665725
end
666726
end
667727
end

‎test/unit/image_element_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ class ImageElementTest < Minitest::Test
1919
include AppiumLibCoreTest::Mock
2020

2121
def setup
22-
@core ||= ::Appium::Core.for(Caps.ios)
22+
@core ||= ::Appium::Core.for(Caps.android)
23+
@driver ||= android_mock_create_session_w3c
2324
end
2425

2526
def test_w3c
26-
driver ||= ios_mock_create_session_w3c
27-
2827
stub_request(:post, "#{SESSION}/element")
2928
.with(body: { using: '-image', value: 'base64 string' }.to_json)
3029
.to_return(headers: HEADER, status: 200, body: { value:
31-
{ 'element-6066-11e4-a52e-4f735466cecf':
30+
{ ::Appium::Core::Element::ELEMENT_KEY =>
3231
'appium-image-element-bb24f75c-5c15-478d-bb38-c003788aa5f8' } }.to_json)
3332

34-
e = driver.find_element :image, 'base64 string'
33+
e = @driver.find_element :image, 'base64 string'
3534

3635
assert_requested(:post, "#{SESSION}/element", times: 1)
36+
assert_equal ::Appium::Core::Element, e.class
3737
assert_equal 'appium-image-element-bb24f75c-5c15-478d-bb38-c003788aa5f8', e.id
3838
end
3939
end

0 commit comments

Comments
 (0)
Please sign in to comment.