lundi 25 novembre 2019

Create a test base page for calling desired capabilities

I was hoping for some help setting up my test frame work as its causing me issue. Im currently using zalenium in conjunction with my selenium tests. Currently im setting the desired capabilities in the @BeforeTest section of my tests:

@BeforeTest
@Parameters("browser")
public void setup(String br)throws MalformedURLException {


    de = new DesiredCapabilities();
    if  (br.equals("chrome")) {
        de.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
        de.setCapability(CapabilityType.PLATFORM_NAME, org.openqa.selenium.Platform.LINUX);
    }
    else if(br.equals("firefox")){

        de.setCapability(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
        de.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);

    }

    URL url = new URL("http://localhost:4444/wd/hub");

    driver = new RemoteWebDriver(url,de);

    driver.get(URL);

This allows me to run my testing in the docker environment and not on my local machine and is working correctly.

However i would like to create a base for these capabilities so i don't have to keep stating the desired capabilities for each test.

I want to do this also because I would like to set up separate classes for each page. Currently when i try this im getting a null pointer exception because the driver isnt declared. I tried to inject the Remote webdriver like so:

@Test
public void loginTest( RemoteWebdriver driver){


    WebElement user_account_menu = driver.findElement(By.cssSelector("[data-user-account-settings-button]"));

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.elementToBeClickable(user_account_menu));

    user_account_menu.click();
    System.out.println("Login clicked successfully");

}

Im receiving the error: Cannot inject @Test annotated Method [loginTest] with [class org.openqa.selenium.remote.RemoteWebDriver

So im basically trying to figure out how i can set up these capabilities for the driver in a class and then extend them onto my tests.

Aucun commentaire:

Enregistrer un commentaire