几年前,我正在忙于一些工作,客户希望了解如何解决现实世界中的问题。 他们要求我自动化woot.com网站上的某些任务。
他们的任务是访问各个网站,并阅读当天商品的名称和价格。
我写了一些Selenium代码,以为可以将其张贴在这里,以防任何对任何人有用。
我得到了这份工作,所以这不会太糟糕。
首先,我定义了一个界面来表示一个woot页面:
package uk.co.doogle;
import com.thoughtworks.selenium.Selenium;
/**
* This interface defines the methods we must implement for classes
* of type Woot. Woot web sites have one item for sale every 24 hours.
* @author Tony
*/
public interface Woot {
/**
* Defines the interface of the method we use to get the price
* of the item for sale on a Woot website
* @param selenium the selenium object we pass in which is used to interact
* with the browser/web page
* @return String representation of the price of the item for sale
*/
public String getPrice(Selenium selenium);
/**
* Defines the interface of the method we use to get the product name
* of the item for sale on a Woot website
* @param selenium the selenium object we pass in which is used to interact
* with the browser/web page
* @return String representation of the product name of the item for sale
*/
public String getProductName(Selenium selenium);
}
然后,我多次实现了此接口,以表示各种woot页面的实际行为–例如,如果是winewoot页面: