Как определить действия в моделировании объекта страницы - PullRequest
0 голосов
/ 27 августа 2018

Я новичок в селене.Я пытался получить доступ к menu-> sub-menu в PageObject Modeling.

Мне нужно щелкнуть пункт меню и пункт подменю, который появляется динамически.

Я проходил через StackOverflow, и в одном из разрешений было упомянуто о том, чтобы написать Actions как

      Actions actions = new Actions(driver);
  actions.moveToElement(currentOpenings).build().perform();
  WebDriverWait wait = new WebDriverWait(driver,10); 
  wait.until(ExpectedConditions.elementToBeClickable(ausJobsSubmenu));

Однако я не могу передать драйвер в конструкторе.если я передам конструктор, я получаю проблемы при запуске этого скрипта.Ошибка ниже

FAILED: checkLinks java.lang.Error: Unresolved compilation problem: 
The method HomePageLinksClick(WebDriver) in the type HomePageLinksTest is not applicable for the arguments ()

Если я включаю драйвер WebDriver в конструктор в качестве параметра, мой класс страницы не принимает это как параметр.Может кто-нибудь помочь?

Класс страницы

package au.com.sreetechconsulting.Pages;
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 au.com.sreetechconsulting.TestCases.HomePageLinksTest;
public class HomePage {
 public WebDriver driver;
 @BeforeTest
 public void openBrowser() {
    System.setProperty("webdriver.chrome.driver", "chromedriver.exe");

    driver = new ChromeDriver(); 

    driver.manage().window().maximize();

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


    driver.get("http://www.sreetechconsulting.com.au/");
}
@Test 
public void checkLinks() {
    HomePageLinksTest linkClick = new HomePageLinksTest(driver);

    linkClick.HomePageLinksClick();

 }
}

Класс тестовой страницы

package au.com.sreetechconsulting.TestCases;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class HomePageLinksTest {

  @FindBy(css="#header > div.container > div > div.col-md-9.main-nav > nav > ul > li:nth-child(2) > a")
 private WebElement currentOpenings;

  @FindBy(css="#header > div.container > div > div.col-md-9.main-nav > nav > ul > li:nth-child(2) > ul > li:nth-child(1) > a")
  private WebElement ausJobsSubmenu;

  public HomePageLinksTest (WebDriver driver) {
     PageFactory.initElements(driver, this);

  }

  public void HomePageLinksClick() {


   //currentOpenings.click();
    Actions actions = new Actions(driver);
    actions.moveToElement(currentOpenings).build().perform();
    WebDriverWait wait = new WebDriverWait(driver,10); 
    wait.until(ExpectedConditions.elementToBeClickable(ausJobsSubmenu));
  }

}

1 Ответ

0 голосов
/ 28 августа 2018

Вы можете сохранить driver в качестве члена класса от конструктора

public class HomePageLinksTest {

    private WebDriver driver;

    public HomePageLinksTest (WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public void HomePageLinksClick() {
        //currentOpenings.click();
        Actions actions = new Actions(driver);
        actions.moveToElement(currentOpenings).build().perform();
        WebDriverWait wait = new WebDriverWait(driver,10); 
        wait.until(ExpectedConditions.elementToBeClickable(ausJobsSubmenu));
    }
}

А в тесте использовать его вот так

@Test 
public void checkLinks() {
    HomePageLinksTest linkClick = new HomePageLinksTest(driver);
    linkClick.HomePageLinksClick();
 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...