diff --git a/library/test/selenium/examples/example_search.e b/library/test/selenium/examples/example_search.e index 6835d9fe..727e10a5 100644 --- a/library/test/selenium/examples/example_search.e +++ b/library/test/selenium/examples/example_search.e @@ -6,7 +6,16 @@ note class EXAMPLE_SEARCH - + inherit + ANY + redefine + default_create + end +feature + default_create + do + search + end feature -- Example search local diff --git a/library/test/selenium/examples/examples.ecf b/library/test/selenium/examples/examples.ecf index ec7013d0..ae652ff0 100644 --- a/library/test/selenium/examples/examples.ecf +++ b/library/test/selenium/examples/examples.ecf @@ -18,4 +18,16 @@ + + + + + + + + + + + + diff --git a/library/test/selenium/examples/find_element_class.e b/library/test/selenium/examples/find_element_class.e new file mode 100644 index 00000000..32b59578 --- /dev/null +++ b/library/test/selenium/examples/find_element_class.e @@ -0,0 +1,84 @@ +note + description: "Using the class attribute to find elements. The class attribute is provided to apply CSS to an element." + +class + FIND_ELEMENT_CLASS + +inherit + + ANY + redefine + default_create + end + +create + default_create + +feature + + default_create + do + search + end + +feature -- Search by id + + search + local + web_driver: WEB_DRIVER + wait: WEB_DRIVER_WAIT + capabilities : SE_CAPABILITIES + do + -- Create desired capabilities + + create capabilities.make + capabilities.set_css_selectors_enabled (True) + capabilities.set_browser_name ("chrome") + + --Create a new instance of a Web driver + create web_driver.make + + -- Start session with chrome and capabilities + web_driver.start_session_chrome_with_desired_capabilities (capabilities) + + -- Go to EiffelRoom login page + web_driver.to_url ("http://www.eiffelroom.com/user?destination=front") + + + -- Find the user name, password element by its id and submit + if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-name")) as l_user and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-pass")) as l_pass and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-submit")) as l_form then + l_user.send_keys (<<"test">>) + l_pass.send_keys (<<"pass">>) + l_form.submit + end + + -- After submit, there is an error message, and we still are in the same page + + -- Wait for the page to load, timeout after 10 seconds + create wait.make (web_driver,10) + wait.until_when (agent expected_title (web_driver, "User account")) + + + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) + end + + if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).class_name ("title")) as l_title then + if attached l_title.get_text as l_text then + print ("%NDisplay:" + l_text) + + end + end + -- close the window + web_driver.window_close + end + + + expected_title (driver : WEB_DRIVER; title : STRING_32) : BOOLEAN + do + if attached {STRING_32} driver.get_page_tile as l_title and then l_title.has_substring (title) then + Result := True + end + end + +end diff --git a/library/test/selenium/examples/find_element_id.e b/library/test/selenium/examples/find_element_id.e new file mode 100644 index 00000000..ebadbe5d --- /dev/null +++ b/library/test/selenium/examples/find_element_id.e @@ -0,0 +1,53 @@ +note + description: "Using the id attribute is the most preferable way to locate elements on a page." + +class + FIND_ELEMENT_ID + +inherit + + ANY + redefine + default_create + end + +create + default_create + +feature + + default_create + do + search + end + +feature -- Search by id + + search + local + web_driver: WEB_DRIVER + wait: WEB_DRIVER_WAIT + do + --Create a new instance of a Web driver + create web_driver.make + + -- Start session with chrome + web_driver.start_session_chrome + + -- Go to EiffelRoom login page + web_driver.to_url ("http://www.eiffelroom.com/user?destination=front") + + -- Find the user name, password element by its id and submit + if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-name")) as l_user and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-pass")) as l_pass and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-submit")) as l_form then + l_user.send_keys (<<"test">>) + l_pass.send_keys (<<"pass">>) + l_form.submit + end + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) + end + -- close the window + web_driver.window_close + end + +end diff --git a/library/test/selenium/examples/find_element_name.e b/library/test/selenium/examples/find_element_name.e new file mode 100644 index 00000000..1d8ed37f --- /dev/null +++ b/library/test/selenium/examples/find_element_name.e @@ -0,0 +1,57 @@ +note + description: "[ + Unlike find_element_id, find by name attribute may not be unique on a page. We might find multiple elements + with similar name attributes,if that happends, the first element on the page + will be selected, which may not be the element we are looking for. + ]" + +class + FIND_ELEMENT_NAME + +inherit + + ANY + redefine + default_create + end + +create + default_create + +feature + + default_create + do + search + end + +feature -- Search by id + + search + local + web_driver: WEB_DRIVER + wait: WEB_DRIVER_WAIT + do + --Create a new instance of a Web driver + create web_driver.make + + -- Start session with chrome + web_driver.start_session_chrome + + -- Go to EiffelRoom login page + web_driver.to_url ("http://www.eiffelroom.com/user?destination=front") + + -- Find the user name, password element by its name and submit + if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).name ("name")) as l_user and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).name ("pass")) as l_pass and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).name ("op")) as l_form then + l_user.send_keys (<<"test">>) + l_pass.send_keys (<<"pass">>) + l_form.submit + end + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) + end + -- close the window + web_driver.window_close + end + +end