Sunday, December 6, 2015

תראו כמה מסמרים!

Look at all these nails!

אמירה מפורסמת טוענת שכשיש לך פטיש ביד, כל דבר נראה כמו מסמר. מה ששוכחים לומר, הוא שכשאין לך פטיש בארגז הכלים, מאוד קל לפספס את המסמרים שבאמת נמצאים שם.

לפני שמונה חודשים, אחרי שהגעתי לאחד ממפגשי סלניום שמארגנים אדם כרמי ואורן רובין, ושמעתי שם את דייב הפנר  שהמליץ על שילוב על browsermob proxy (אגב, אם אתם עובדים עם סלניום וטרם שמעתם עליו, אתם כנראה רוצים להירשם כאן ולקבל ממנו טיפ סלניום שבועי בדוא"ל), התחלתי לקרוא קצת והחלטתי לנסות את הרעיון. השקעתי כמה שעות בהוכחת היתכנות - ואחרי שזה עבד, התחלתי להסתבך עם חיבור הפרוקסי לפרוייקט האמיתי שלנו (התנגשות של ספריות יכולה לגרום לתופעות מרגיזות מאוד) אבל בסופו של דבר, אחרי עוד כמה שעות שהתפזרו על פני כמה חודשים - כי תמיד יש משהו דחוף יותר מאשר יוזמות עצמאיות - הצלחתי לפתור את כל הבעיות ולהריץ את הבדיקות דרך פרוקסי.
כשהצגתי את היכולות לשאר הצוות, הכנתי הדגמת יכולת פשוטה, כזו שלקחה לי בערך רבע שעה, כולל עקומת הלימוד שנדרשה - עברתי על כל הבקשות שנשלחו וחיפשתי תשובות HTTP לא סטנדרטיות. התוצאה? גיליתי שיש לנו כל מיני דפים שמבקשים משאבים שלא אמורים להיות להם, אבל הסיבה לכך קבורה כל כך עמוק בקוד עתיק שהחלטנו לא לגעת בזה כרגע.
אבל זה החלק המעניין פחות - מה שמעניין יותר הוא שאחרי ההדגמה הקצרה לצוות, פתאום התחילו לעלות לנו כל מיני רעיונות שלא חשבנו עליהם קודם. מעבר לשיפורים שהתכוונו להוסיף לבדיקות הקיימות שלנו, עלו פתאום רעיוונת לכל מיני בדיקות חדשות לגמרי שקל לבצע באמצעות הכלי החדש והנוצץ שהוספנו. עצם העובדה שיש לנו עכשיו כוח שלא היה לנו קודם חשפה בפנינו מרחב אפשרויות חדש, וחלק ממרחב האפשרויות הזה מעניין. הוא היה מעניין גם לפני שהתחלנו להשתמש בכלי חדש, אבל אף אחד מאיתנו לא חשב עליו, כי מול העיניים היו מונחים לנו דברים אחרים. היה לנו את הממשק מול סלניום שמתעסק במה נמצא או לא נמצא בדף ובאלמנטים השונים בDOM, היו לנו בדיקות מול מסד הנתונים שהתרכזו במה נכתב לכל מקום, והיו לנו שריקות של קבצי הלוג - ולמרות שאנחנו משפרים את היכולות האלה באופן קבוע, גם פספסנו (ואנחנו עדיין מפספסים) עולם שלם מסביבנו.
באופן אישי, זו הייתה חוויה חינוכית מאוד. זו תזכורת מצויינת לכך שתמיד יש עוד מקומות להסתכל עליהם - מטא-דאטה, צריכת זיכרון, איך באמת משתמשים בתוכנה שלנו במציאות, ועוד מיליון ואחד מקומות אחרים.  הרחבה של היכולות שלנו באזורים שהיו נקודות עיוורות בעבר שיפרה באופן כמעט מיידי גם את הבדיקות שלנו וגם את הרעיונות שעולים לנו -אני לא יכול לחשוב על שום סיבה שזה לא יפעל באותו אופן אצלכם.


----------------------------------------------

A famous proverb states that if all you have is a hammer the everything looks like a nail. What is also true but less frequently heard is that when you don't have a hammer in your toolbox, you miss out a lot a nails. 
Eight months ago, I went to one of the local selenium meetups organized by Adam Carmi (Co-Founder of Applitools) and Oren Rubin (Founder of Testim) where I've heard Dave Haeffner that recommended to incorporate Browsermob proxy into Selenium tests (By the way, if you are working with Selenium and have not yet heard of Dave, you probably want to register here to his weekly Selenium tips). So, I did some reading and decided to give it a try. I did a quick proof-of concept and then went struggling to try and stitch BMP to our project (Library conflicts can cause all sorts of insidious problems) - Finally, after several hours of work that spread over several months - as there is always something more urgent to do than an independent pursuit of an idea - I managed to run our tests through a proxy. 
The next step was to show off to my team - I spent around 15 minutes (including the learning curve) and added a simple check: for every request checked the HTTP response status and printed all the unexpected ones. As a result I found out that some pages are asking for resources without reason (the reason for that is buried under layers upon layers of legacy code - so we have decided to leave it as is). 
At any rate, what I did or didn't find is the least interesting thing around here, the more interesting phenomenon was that once we accepted the new capabilities that we now had, we suddenly started having all those new ideas of things we now can and should do - all of them are valid and valuable checks that we did not previously thought of - on top of the improvements we intended for our existing tests, there were some new tests we came up with just because we now could easily do them with our new and shiny tool. Previously, we have not thought about them because we had other things laid out in front of our eyes. We had selenium API that is all about DOM elements, we had database checks that are focused around what is written where, and we were checking our logs as well. We are improving our work with them constantly, but in the meanwhile we missed (and are still missing) a whole world around us. 
For me, this experience was very educating. I can definitely use this as a reminder to me that there are always more areas to look at - metadata, memory consumption, the actual usage of the software in the real world, and a million other things. Expanding our capabilities in what was previously a blindspot has almost instantly improved our testing and our ideas - I see no reason it won't do the same for you. 

No comments:

Post a Comment