Industry Grade Selenium Webdrive Template

Industry Grade Selenium Webdrive Template



I've recently started learning about selenium WebDriver, and I've learned a lot of stuff from different sources but I don't have a good idea of how should a clean/professional grade script should look like and how should it's content be written.



This is an example of a login that I've created as a test, what could I change?


package Facebook;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class Login

WebDriver driver = new ChromeDriver();

public void login() throws InterruptedException

driver.get("http://www.facebook.com");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement user = driver.findElement(By.id("email"));
WebElement password = driver.findElement(By.id("pass"));
user.sendKeys("user_test");
password.sendKeys("password_test");
Thread.sleep(3000);
user.clear();
password.clear();

WebElement submit = driver.findElement(By.id("u_0_u"));

if(submit.isDisplayed())

System.out.println("u001B31;1m Succes");

else

System.out.println("u001B31;2m Fail");



public static void main(String args) throws InterruptedException
Login obj = new Login();
obj.login();






It is preferred if you can post separate questions instead of combining your questions into one. That way, it helps the people answering your question and also others hunting for at least one of your questions. Thanks! I removed your question about printing text in different colors. That question has been answered before on this site and distracts from your main question about Selenium.
– JeffC
Aug 20 at 13:41





1 Answer
1



You should spend some time learning about the Page Object Model. If you are going to build more than a few tests, it will be a significant boost to organization, keeping your code clean, and lessening the maintenance burden.



Avoid Thread.sleep() and implicit waits. Instead prefer WebDriverWait.


Thread.sleep()


WebDriverWait



Don't write your own logging/reporting. Instead use JUnit or TestNG. They are well established and will save you a lot of time with not only logging but handling organization of your tests, executions, reporting, etc.



NOTE: Be careful about questions on SO that sound like asking for a code review. There's a whole other site for that, http://codereview.stackexchange.com.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj