Ruby

Apart from Technical Topics, increasingly i find myself wanting to write about other topics that interests me - Entreprenuership and Business, Leadership, Africa, Service Industry (e.g Hotels, Restaurant). My writings would always represent my opinions and it might change from time to time.

Watir: Search for elements on page using multiple attributes

I ran into a situation today where i wanted to scan through a page and return a table based on the table matching 3 attributes Before: browser.tables.find do |table| table.class_name == ‘my_class_name’ and table.cell(:class, ‘class_1_name’).text == ‘some_text_1’ and table.cell(:class, ‘class_2_name’).text == ‘some_text_2’ end This was taking about 3minutes as there were about 86tables on this page under test. I was worried but the tables on this page was gonna increase with time which meant the time for this stage of the test was bound to increase.

Active Record find by Column Name

In recent days been doing a lot of ruby, which means i tend to use Active Record as well. I had written some scripts where i was selecting records that matched a criteria such as: @table1.table2s.select{|e| e.column_name == 1234} but as i need to sort my result and also give some more conditions to filter the data, i need alternatives to this above query and i ended up with the two lines of code below: