官术网_书友最值得收藏!

Chapter 2. The Spaghetti Pattern

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."

--Martin Golding

Writing and maintaining any form of software is like fighting entropy; given enough time and changes, any code base will gradually decline into disorder. A test suite is a closed system; if you do not provide energy in constant upkeep and planning, the suite will deteriorate and will fail constantly. Every new feature and line of code added to our website makes our test suite obsolete. The only way to fight back these natural forces is to constantly upgrade and improve existing tests.

In this chapter, we will start to grow our test suite organically and take a look at an anti-pattern called the Spaghetti pattern. Along the way, we will pick up some more basic skills, such as using XPath and CSS selectors to locate the elements on a web page.

Note

The term anti-pattern was inspired by a great book on software design called Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, published by Addison-Wesley Professional and is roughly defined as a common practice, which seems appropriate for current situation, but has a lot of unintended side effects. Furthermore, a better solution for the problem does exist, but is typically ignored in favor of the initial obvious but wrong solution.

In order to write the new tests in this chapter, we will cover the following topics:

  • Spaghetti pattern
  • Element locator strategies
  • XPath and CSS selector query languages
  • Relative and absolute path
  • Browser inspector tool
  • Test run order
  • Chain Linked pattern
  • Big Ball of Mud pattern
主站蜘蛛池模板: 延边| 东乌珠穆沁旗| 栖霞市| 霞浦县| 共和县| 新民市| 旌德县| 桐乡市| 横山县| 甘谷县| 乐清市| 雷州市| 奈曼旗| 无为县| 杭锦旗| 章丘市| 碌曲县| 龙海市| 甘肃省| 汾阳市| 兴文县| 镇坪县| 芦山县| 保亭| 大田县| 兴仁县| 兴文县| 互助| 泉州市| 高密市| 铜川市| 奉贤区| 旬阳县| 靖远县| 乾安县| 新化县| 乌苏市| 南宫市| 加查县| 周口市| 卢湾区|