Code review of Selenium java. Примеры говнокода из реальных проектов и примеры его улучшения. Не обязательно идеальные, но тем не менее лучшие )
Wrong way:
//Wait 15 min till e-Mail waiting time
logger.info("e-Mail sent out, wait 15 min till it will be on patrick@test.com");
Thread.sleep(900000);
logger.info("15 min left go check Mail");
Good way:
//check that e-mail was received
By searchButtonBy = By.xpath("//td/input[@name='searchbutton']");
By subjectBy = By.xpath("//a[contains(text(),'"+ emailSubject +"')]");
int count = driver.findElement(subjectBy).size();
int j = 1;
logger.info("Check e-mail every 10 sec. during 10 min.");
while ((count < 1) && (j < 60)) {
// check e-mail during 3 min and every 10 sec.
j++;
Thread.sleep(10000);
new driver.findElement(searchButtonBy).click();
count = driver.findElements(subjectBy).size();
logger.info(j +". number of emails - " + count);
}
if (count < 1) throw new Exception("There is no e-mail, something went wrong.");