lundi 2 juillet 2018

How to run a class which runs multiple Selenium classes?

I have a test which I would like to know if it's possible to run with one click. What I mean is I have a class which runs e other classes and another one which runs one (I am doing research right now, so the tests ran are quite basic. so I have the class

package testNGresearch;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import multipleTest.Loginer;

public class AllLoginTestsNG extends OneClickTest{

    public static WebDriver driver;
    String baseUrl = "https://9gag.com/";
    @BeforeTest
    public void openBrowser() {
        System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }

    @Test(priority = 1)
    public void GetUrl() throws InterruptedException {
        driver.get(baseUrl);
        Thread.sleep(1500);
        Loginer.login(driver);
    }
    @Test(priority = 2)
    public void clickSignUp() {
        Loginer1.signUp(driver);
    }
    @Test(priority = 3)
    public void cancelSignUp() {
        Loginer2.cancelSignUp(driver);
        driver.close();
    }
    @Test(priority=4)
    public void navigationTests() throws InterruptedException {
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get(baseUrl);
        Thread.sleep(1500);
        NavigationTestNG.navigation(driver);
    }
}

and then another one (seperate file)

package testNGresearch;

import org.openqa.selenium.By;
import org.testng.annotations.Test;

public class Loginer extends AllLoginTestsNG{


    @Test
    public void login() {
        driver.findElement(By.xpath("/html/body/div[7]/div[1]/div[2]/div/div[3]/button[2]/span")).click();
        driver.findElement(By.xpath("//*[@id=\"jsid-login-button\"]")).click();
        driver.findElement(By.xpath("//*[@id=\"login-email-name\"]")).sendKeys("someuser");
        driver.findElement(By.xpath("//*[@id=\"login-email-password\"]")).sendKeys("somepass");
        driver.findElement(By.xpath("//*[@id=\"login-email\"]/div[3]/input")).click();
    }
}

Then the second one which is ran by the AllLogin class

package testNGresearch;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;

public class Loginer1 extends AllLoginTestsNG {

    @Test
    public static void signUp(WebDriver driver) {
        driver.findElement(By.xpath("//*[@id=\"jsid-signup-button\"]")).click();
    }

}

Now I have a class AllNavigation

package testNGresearch;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class AllNavigationTestsNG extends AllLoginTestsNG {

    public static WebDriver driver;
    String baseUrl = "https://9gag.com/";
    @BeforeTest
    public void openBrowser() {
        System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }
    @Test(priority = 1)
    public void startNavigating (WebDriver driver) throws InterruptedException {
        driver.get(baseUrl);
        Thread.sleep(1500);
        NavigationTestNG.navigation(driver);
    }
}

Which runs

package testNGresearch;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;

public class NavigationTestNG extends AllNavigationTestsNG {

    @Test (priority = 1)
    public static void navigation(WebDriver driver) throws InterruptedException {
        Thread.sleep(500);
        driver.findElement(By.xpath("/html/body/div[7]/div[1]/div[2]/div/div[3]/button[2]/span")).click();
        Thread.sleep(500);
        driver.findElement(By.xpath("//*[@id=\"top-nav\"]/div/a")).click();
    }
}

So the question is - Is it possible to create a class which runs the AllLogin class and the AllNavigationTestNG class (which makes them run one after another) I created a OneClickTest class which throws errors

package testNGresearch;

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

public class OneClickTest {

    public static void main(String[] args) {

        WebDriver driver;
        AllLoginTestsNG.allLogin(driver);
        AllNavigationTestsNG.anotherLogin(driver);
    }
}

Aucun commentaire:

Enregistrer un commentaire