|
| 1 | +# This is the actual test file |
| 2 | +# Here I used Page Object Model to declare the locators and use within the tests |
| 3 | +# This test skeleton structure is built to look similar with rspec test structure |
1 | 4 | require_relative 'spec_helper.rb' |
2 | 5 | require_relative '../pages/home.rb' |
3 | 6 | require_relative '../pages/search_listing.rb' |
|
6 | 9 | require 'yaml' |
7 | 10 | include Pages |
8 | 11 |
|
| 12 | +# Each test file should have one describe block with the text that states the higher level module which is going to be tested |
9 | 13 | describe("Find Professionals in Upwork") do |
10 | 14 |
|
| 15 | + # Before all block where we need initialize all the pages and load the test data that is going to be used across this file |
11 | 16 | before_all do |
12 | 17 | @@find_prof_page = Home.new |
13 | 18 | @@search_listing = SearchListing.new |
|
16 | 21 | @@test_data = YAML.load_file(Dir.pwd + '/test-data/find_professionals.yml') |
17 | 22 | end |
18 | 23 |
|
| 24 | + # After all Make sure the browser driver initialized is quit properly |
19 | 25 | after_all do |
20 | 26 | @@driver.quit |
21 | 27 | end |
22 | 28 |
|
| 29 | + # This is added in additional to the rspec's structure |
| 30 | + # Here you can specify multiple search_key in the test_data yaml file in array format |
| 31 | + # This test will run iteratively for all the search key's and log the results |
23 | 32 | @@test_data['search_keyword'].each do |search_key| |
| 33 | + # This is where the actual test starts |
| 34 | + # A file can have multiple `it` statements within a `describe` block |
24 | 35 | it("Find professionals using search option in Upwork") do |
| 36 | + # Each step defines an important action that is made in the browser |
| 37 | + # Each step will be logged to the console, |
| 38 | + # So its better to have only the important test steps that has to be noted by manual person here |
25 | 39 | step("Run " + Config.browser + " brower with headless as " + Config.headless.to_s) do |
26 | 40 | @@driver = Driver.new |
27 | 41 | end |
|
31 | 45 | step("Navigate to Upwork website - " + Config.url) do |
32 | 46 | @@driver.get(Config.url) |
33 | 47 | if @@captcha.captcha.is_present_with_wait?(10) |
34 | | - sleep(60) |
| 48 | + sleep(60) # To handle the captcha page |
35 | 49 | @@captcha.handle_captcha_page |
36 | 50 | end |
37 | 51 | expect_to_equal(@@find_prof_page.find_professionals_and_agencies_text_box.is_present_with_wait?(30), true, "Home page is displayed") |
|
48 | 62 | @@driver.clear_cookies |
49 | 63 | @@driver.get(@@test_data["url_with_search_key"] + search_key) |
50 | 64 | end |
51 | | - sleep(60) if @@captcha.captcha.is_present_with_wait?(10) |
| 65 | + sleep(60) if @@captcha.captcha.is_present_with_wait?(10) # To handle the captcha page |
52 | 66 | expect_to_equal(@@search_listing.is_search_listing_displayed?, true, "Search listing page is displayed") |
53 | 67 | end |
54 | 68 | step("Parsing the first page with search results and storing the results in hash of hash format") do |
55 | 69 | @@result_hash = @@search_listing.parse_results_page_and_store_values |
56 | | - Log.info("Search results parsed data -> #{@@result_hash}") |
| 70 | + Log.info("Search results parsed data -> #{@@result_hash}") # Log.info methods wont be printed in the stdout, one can change the logger level to get these |
57 | 71 | end |
58 | 72 | step("Validate the results hash along with the search key that is used to get the results") do |
| 73 | + # Each freelancer's detail is matched with the search key |
| 74 | + # And if the key word is not matched with any of the attributes, fail log will be printed |
| 75 | + # Else pass log will be prited for that freelancer with the name |
| 76 | + # log.info methods will give indepth comparison, if needed one can change the logger level |
59 | 77 | @@result_hash.each do |key, value| |
60 | 78 | pass_result = {} |
61 | 79 | fail_result = {} |
|
88 | 106 | end |
89 | 107 | end |
90 | 108 | step("Click on the random profile from the search result and fetch the freelancer details from the freelancers preview page") do |
91 | | - @@profile_count = rand(1..10) |
| 109 | + @@profile_count = rand(1..10) # clicking on random profile from the list dispalyed |
92 | 110 | @@search_listing.click_on_freelancer_profile(@@profile_count) |
93 | | - if !@@profile_preview.is_profile_preview_displayed? |
| 111 | + if !@@profile_preview.is_profile_preview_displayed? # To handle the captcha page |
94 | 112 | @@driver.quit |
95 | 113 | @@driver = Driver.new |
96 | 114 | @@driver.clear_cookies |
|
102 | 120 | step("Fetch details from the freelancers profile preview and compare it with the details dispalyed in search results page") do |
103 | 121 | preview_hash = @@profile_preview.create_hash_for_client_details |
104 | 122 | Log.info("Freelancer profile fetched details -> #{preview_hash}") |
| 123 | + # Following are the assertions for the details fetched from the search list page and the freelancer profile preview page |
| 124 | + # Each attributes are having different format in the UI, hence while fetching each one will have different structure |
| 125 | + # Some of them are modifed to make it compatible for comparing |
105 | 126 | expect_to_equal(@@result_hash[@@profile_count][:name], preview_hash[:name], "Profile preview and search listing details match for name with values #{@@result_hash[@@profile_count][:name]} == #{preview_hash[:name]}") |
106 | 127 | expect_to_equal(@@result_hash[@@profile_count][:title], preview_hash[:title], "Profile preview and search listing details match for title with values #{@@result_hash[@@profile_count][:title]} == #{preview_hash[:title]}") |
107 | 128 | expect_to_equal(@@result_hash[@@profile_count][:country], preview_hash[:country], "Profile preview and search listing details match for country with values #{@@result_hash[@@profile_count][:country]} == #{preview_hash[:country]}") |
108 | | - expect_to_equal(preview_hash[:earned]&.split(" ")[0], @@result_hash[@@profile_count][:earned]&.split("\n")[0], "Profile preview and search listing details match for earned with values #{@@result_hash[@@profile_count][:earned]} == #{preview_hash[:earned]&.delete("\n")}") if @@result_hash[@@profile_count][:earned] |
109 | | - expect_to_equal(@@result_hash[@@profile_count][:overview]&.delete("\n")&.delete(' '), preview_hash[:overview]&.delete("\n")&.delete(' '), "Profile preview and search listing details match for overview with values #{@@result_hash[@@profile_count][:overview]&.delete("\n")} == #{preview_hash[:overview]&.delete("\n")}") |
| 129 | + expect_to_equal(preview_hash[:earned]&.split(" ")[0], @@result_hash[@@profile_count][:earned]&.split("\n")[0].split(" ")[0], "Profile preview and search listing details match for earned with values #{@@result_hash[@@profile_count][:earned]} == #{preview_hash[:earned]&.delete("\n")}") if @@result_hash[@@profile_count][:earned] |
| 130 | + expect_to_equal(@@result_hash[@@profile_count][:overview]&.delete("\n")&.delete(' '), preview_hash[:overview]&.delete("\n")&.delete(' ')&.split("lessShowlesstext")[0], "Profile preview and search listing details match for overview with values #{@@result_hash[@@profile_count][:overview]&.delete("\n")} == #{preview_hash[:overview]&.delete("\n")}") |
110 | 131 | expect_to_equal(@@result_hash[@@profile_count][:upskill_tags], preview_hash[:upskill_tags], "Profile preview and search listing details match for upskill_tags with values #{@@result_hash[@@profile_count][:upskill_tags]} == #{preview_hash[:upskill_tags]}") |
111 | 132 | expect_to_equal(@@result_hash[@@profile_count][:price]&.delete(' '), preview_hash[:price]&.delete(' '), "Profile preview and search listing details match for price with values #{@@result_hash[@@profile_count][:price]&.delete(' ')} == #{preview_hash[:price]&.delete(' ')}") |
112 | | - expect_to_equal((preview_hash[:success_rate]&.delete("\n")&.delete(' ')&.include? @@result_hash[@@profile_count][:success_rate]&.delete(' ')), true, "Profile preview and search listing details match for success_rate with values #{preview_hash[:success_rate]&.delete("\n")} == #{@@result_hash[@@profile_count][:success_rate]&.delete(' ')}") |
| 133 | + expect_to_equal((preview_hash[:success_rate]&.delete("\n")&.delete(' ')&.include? @@result_hash[@@profile_count][:success_rate]&.delete(' ')), true, "Profile preview and search listing details match for success_rate with values #{preview_hash[:success_rate]&.delete("\n").to_s} == #{@@result_hash[@@profile_count][:success_rate]&.delete(' ').to_s}") |
113 | 134 | expect_to_equal(@@result_hash[@@profile_count][:associated_with]&.split("\n")[1], preview_hash[:associated_with]&.split("\n")[0], "Profile preview and search listing details match for associated_with with values #{@@result_hash[@@profile_count][:associated_with]&.split("\n")[1]} == #{preview_hash[:associated_with]&.split("\n")[0]}") if @@result_hash[@@profile_count][:associated_with] |
114 | 135 | end |
115 | 136 | end |
|
0 commit comments