2

I worked in selenium for 3 months. I had written some code. In my company I am the only tester. Nobody knows about the testing. But I couldn't find a solution for is it my code is correct or not. I tested the login module anybody please correct my code. A senior tester told me that the test script are fine. He asked me that What are you testing with this? Actually I want to find a solution for this. what should I do? What I will test for my project? Is there any If condition statement I miss? Here is my code..

package QberLogin;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;


public class AdminLogin 
{


    public static void main(String[] args) throws Exception 
    {


        System.setProperty("webdriver.firefox.marionette", "pathToGeckodriver");
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("http://54.68.159.204/qmsadm");
        driver.manage().window().maximize();  
        WebElement element = driver.findElement(By.name("username"));

            element.sendKeys("");
            element=driver.findElement(By.name("password"));
            element.sendKeys("");
            Actions action = new Actions(driver); 
           action.sendKeys(Keys.ENTER).build().perform();

           element= driver.findElement(By.linkText("Admin"));
           element.click();
           Thread.sleep(1000);
           element= driver.findElement(By.linkText("Clients"));
           element.click();
           element=driver.findElement(By.name("name"));
           element.sendKeys("Demo");
           element.submit();
           element= driver.findElement(By.xpath("//*[@id='search-container']/a/i"));
           element.click();
           element=driver.findElement(By.id("name"));
           element.sendKeys("Dubai Bank");
           element=driver.findElement(By.id("group_name"));
           element.sendKeys("DBK");
           element=driver.findElement(By.name("address"));
           element.sendKeys("Dubai");
           Select stat=new Select(driver.findElement(By.id("status")));
           stat.selectByVisibleText("active");


           element.submit();
          element= driver.findElement(By.linkText("Hello Sony George"));
           element.click();


           element= driver.findElement(By.linkText("Logout"));
           element.click();

                   driver.close();


    }

}
  • where you stuck? Pls add details – NarendraC Sep 22 '16 at 6:16
  • 1
    @NarendraC ..Hai I edited. – user21268 Sep 22 '16 at 6:31
3

After a quick review of the code I come with the following comments:

The flow of your test should look something like this:

  • Arrange
  • Act
  • Assert

Using the AAA pattern will make it more clear what is part of the test and what is not. Read about AAA here. I always add a comment to show where which part of the test starts.

Alternatively describe your test with

  • Given
  • When
  • Then

Your test name/description could be come GivenIAmLoggedIn_WhenIClickSomeButtons_SomethingHappensThatIVerfify. Read more here.

Leading to this test format:

 @Test
 public void GivenInputABC_WhenIReverseInput_ThenResultIsCBA() {
    // Arrange
    String input = "abc";
    // Act      
    String result = Util.reverse(input);
    // Assert
    assertEquals("cba", result);
 }

The next step to make your test more readable, understandable and maintainable is to wrap it in the Page Object Model. Read more here: http://toolsqa.com/selenium-webdriver/page-object-model/

  • @Niets van Reijmersdai . Thanks.. Is it companies are now using Page object model ? or Which framwork are now the companies are using ? I want to implement it in my company. It will also helpful for me and upcoming new joinees.. – user21268 Sep 22 '16 at 9:10
  • 2
    Page object model is not a framework, but it is the leading GUI test structuring pattern. I cannot advice a Java testing framework since I do not develop in Java anymore for some years. What I can advice is to write automated test in the same language as the application is developed in, because it makes it easier to get help from developers or for developers to write and maintain tests themselves too. Each language has its own popular testing tools and frameworks. Goodluck. – Niels van Reijmersdal Sep 22 '16 at 10:14