2 Mart 2016 Çarşamba

selenium contains

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class testNGExample
{
                public static WebDriver driver;
                public static WebElement tlElement;
               
                @BeforeTest
    public void startDriver()
                {
                                driver= new FirefoxDriver();
                                driver.get("http://localhost/testlink/login.php");
                                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                }
                @Test
    public void test1()
                {
        System.out.println("@Test test1()");
        driver.findElement(By.xpath("//input[@name='tl_login']")).sendKeys("admin");
                               driver.findElement(By.xpath("//input[@name='tl_password']")).sendKeys("admin");
                               driver.findElement(By.xpath("//input[@name='login_submit']")).click();
    }
                 
    @Test(dependsOnMethods="test1")
    public void test2()
    {
                System.out.println("@Test test2()");
                driver.switchTo().frame("mainframe");
                                driver.findElement(By.xpath("//a[contains(text(),'Test Project Management')]")).click();
                                driver.findElement(By.xpath("//input[@name='create']")).click();
                               tlElement=driver.findElement(By.xpath("//input[@name='active']"));
                                tlElement.click();
    }
@AfterTest
    public void stopDriver()
    {
                                driver.switchTo().defaultContent();
                                driver.switchTo().frame("titlebar");
                               driver.findElement(By.xpath("//a[contains(text(),'Logout')]")).click();
                                driver.quit();
  }
}