Skip to content

test: add tests for future #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/functional/android/android/search_context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ def test_uiautomator
e = @driver.find_element :uiautomator, 'new UiSelector().clickable(true)'
assert e
assert_equal "Access'ibility", e.tag_name
assert_equal ::Appium::Core::Element, e.class
end

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

e = @driver.find_elements :viewtag, 'example'
assert_equal 0, e.size
assert_equal ::Appium::Core::Element, e.class
end

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

e.first.click
@driver.find_element :accessibility_id, 'Cloning' # no error
Expand Down Expand Up @@ -94,6 +97,7 @@ def test_viewmatcher
class: 'org.hamcrest.Matchers'
}.to_json
assert_equal "Access'ibility", e.text
assert_equal ::Appium::Core::Element, e.class
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/functional/ios/ios/search_context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ def teardown
def test_predicate
e = @@driver.find_element :predicate, 'wdName == "Buttons"'
assert_equal 'Buttons', e.name
assert_equal ::Appium::Core::Element, e.class
end

def test_class_chain
e = @@driver.find_element :class_chain, "**/XCUIElementTypeWindow[$name == 'Buttons'$]"
assert_equal 'XCUIElementTypeWindow', e.tag_name
assert_equal ::Appium::Core::Element, e.class
end
end
end
Expand Down
84 changes: 72 additions & 12 deletions test/unit/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def test_default_wait
end

def test_default_timeout_for_http_client
@driver ||= android_mock_create_session
driver = android_mock_create_session

assert_equal 999_999, @core.http_client.open_timeout
assert_equal 999_999, @core.http_client.read_timeout
uri = @driver.send(:bridge).http.send(:server_url)
uri = driver.send(:bridge).http.send(:server_url)
assert @core.direct_connect
assert_equal 'http', uri.scheme
assert_equal '127.0.0.1', uri.host
Expand Down Expand Up @@ -623,45 +623,105 @@ def test_listener_with_custom_listener_elements
stub_request(:post, "#{SESSION}/element")
.with(body: { using: 'id', value: 'example' }.to_json)
.to_return(headers: HEADER, status: 200, body: {
value: { ELEMENT: 'element_id_parent' }, sessionId: SESSION, status: 0
value: { ::Appium::Core::Element::ELEMENT_KEY => 'element_id_parent' }, sessionId: SESSION, status: 0
}.to_json)
el = driver.find_element id: 'example'
assert_requested :post, "#{SESSION}/element", times: 1
assert_equal el.class.name, 'Appium::Core::Element'
assert_equal ::Appium::Core::Element, el.class

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

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

# elements
stub_request(:post, "#{SESSION}/elements")
.with(body: { using: 'id', value: 'example' }.to_json)
.to_return(headers: HEADER, status: 200, body: {
value: [{ ELEMENT: 'element_id_parent' }], sessionId: SESSION, status: 0
value: [{ ::Appium::Core::Element::ELEMENT_KEY => 'element_id_parent' }], sessionId: SESSION, status: 0
}.to_json)
els = driver.find_elements id: 'example'
assert_requested :post, "#{SESSION}/elements", times: 1
assert_equal ::Appium::Core::Element, els.first.class

stub_request(:post, "#{SESSION}/element/element_id_parent/elements")
.with(body: { using: 'id', value: 'example2' }.to_json)
.to_return(headers: HEADER, status: 200, body: {
value: [{ ::Appium::Core::Element::ELEMENT_KEY => 'element_id_children' }],
sessionId: SESSION, status: 0
}.to_json)
c_el = els.first.find_elements id: 'example2'
assert_requested :post, "#{SESSION}/element/element_id_parent/elements", times: 1
assert_equal ::Appium::Core::Element, c_el.first.class
end

def test_elements
driver = android_mock_create_session

# element
stub_request(:post, "#{SESSION}/element")
.with(body: { using: 'id', value: 'example' }.to_json)
.to_return(headers: HEADER, status: 200, body: {
value: { ::Appium::Core::Element::ELEMENT_KEY => 'element_id_parent' }, sessionId: SESSION, status: 0
}.to_json)
el = driver.find_element id: 'example'
assert_requested :post, "#{SESSION}/element", times: 1
assert_equal els.first.class.name, 'Appium::Core::Element'
assert_equal ::Appium::Core::Element, el.class

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

stub_request(:post, "#{SESSION}/element/element_id_parent/element")
.with(body: { using: 'id', value: 'example2' }.to_json)
.to_return(headers: HEADER, status: 200, body: {
value: { ::Appium::Core::Element::ELEMENT_KEY => 'element_id_children' }, sessionId: SESSION, status: 0
}.to_json)
c_el = el.find_element id: 'example2'
assert_requested :post, "#{SESSION}/element/element_id_parent/element", times: 1
assert_equal ::Appium::Core::Element, c_el.class

# elements
stub_request(:post, "#{SESSION}/elements")
.with(body: { using: 'id', value: 'example' }.to_json)
.to_return(headers: HEADER, status: 200, body: {
value: [{ ::Appium::Core::Element::ELEMENT_KEY => 'element_id_parent' }], sessionId: SESSION, status: 0
}.to_json)
els = driver.find_elements id: 'example'
assert_requested :post, "#{SESSION}/elements", times: 1
assert_equal ::Appium::Core::Element, els.first.class

stub_request(:post, "#{SESSION}/element/element_id_parent/elements")
.with(body: { using: 'id', value: 'example2' }.to_json)
.to_return(headers: HEADER, status: 200, body: { value: [{ ELEMENT: 'element_id_children' }],
sessionId: SESSION, status: 0 }.to_json)
.to_return(headers: HEADER, status: 200, body: {
value: [{ ::Appium::Core::Element::ELEMENT_KEY => 'element_id_children' }],
sessionId: SESSION, status: 0
}.to_json)
c_el = els.first.find_elements id: 'example2'
assert_requested :post, "#{SESSION}/element/element_id_parent/elements", times: 1
assert_equal c_el.first.class.name, 'Appium::Core::Element'
assert_equal ::Appium::Core::Element, c_el.first.class
end

def test_convert_element
driver = android_mock_create_session
response = { 'element-6066-11e4-a52e-4f735466cecf' => 'test-element-id', 'ELEMENT' => 'test-element-id' }
e = driver.convert_to_element response
assert_equal 'test-element-id', e.id
assert_equal ::Appium::Core::Element, e.class
end
end
end
10 changes: 5 additions & 5 deletions test/unit/image_element_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ class ImageElementTest < Minitest::Test
include AppiumLibCoreTest::Mock

def setup
@core ||= ::Appium::Core.for(Caps.ios)
@core ||= ::Appium::Core.for(Caps.android)
@driver ||= android_mock_create_session_w3c
end

def test_w3c
driver ||= ios_mock_create_session_w3c

stub_request(:post, "#{SESSION}/element")
.with(body: { using: '-image', value: 'base64 string' }.to_json)
.to_return(headers: HEADER, status: 200, body: { value:
{ 'element-6066-11e4-a52e-4f735466cecf':
{ ::Appium::Core::Element::ELEMENT_KEY =>
'appium-image-element-bb24f75c-5c15-478d-bb38-c003788aa5f8' } }.to_json)

e = driver.find_element :image, 'base64 string'
e = @driver.find_element :image, 'base64 string'

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