有人可以幫助我找到一個鏈接字段 測試網站:http://demosite.center/wordpress/wp-login.php 用戶名:admin密碼 :demo123硒場定位
測試用例:點擊左邊有側板的帖子,然後單擊添加新的。
我無法找到登錄後的'帖子'鏈接。腳本是引發此錯誤java.lang.reflect.InvocationTargetException
public class NewPost {
WebDriver driver;
public NewPost(WebDriver localdriver){
this.driver = localdriver;
}
WebElement box=driver.findElement(By.xpath("//*[@id='menu-posts']/a"));
List<WebElement> links = box.findElements(By.tagName("a"));
WebElement posts = links.get(1);
@FindBy(how=How.XPATH, using="//*[@id='wpbody-content']/div[4]/h2/a")
WebElement addNew;
@FindBy(how=How.XPATH, using="//*[@id='title']")
WebElement postTitle;
@FindBy(how=How.XPATH, using="//*[@id='content']")
WebElement content;
@FindBy(how=How.XPATH, using="//*[@id='publish']")
WebElement publishButton;
@FindBy(how=How.ID, using="message")
WebElement postPublishedMsg;
public void addNewPost(String titleText, String contentText){
posts.click();
addNew.click();
postTitle.sendKeys(titleText);
content.sendKeys(contentText);
publishButton.click();
if(postPublishedMsg.getText().contains("Post published")){
System.out.println("Post published successfully");
}
}
}
測試類:
@Test
public class VerifyNewPost {
public void checkNewPost(){
WebDriver driver = BrowserFactory.startBrowser("firefox", "http://demosite.center/wordpress/wp-login.php");
LoginPageNew login_page = PageFactory.initElements(driver, LoginPageNew.class);
login_page.loginWordpress("admin", "demo123");
NewPost post = PageFactory.initElements(driver, NewPost.class);
post.addNewPost("This is new post title", "This is new Post content");
}
}
不是一個真正的答案,但我會推薦Codeception框架。然後它會像這樣簡單:$ I-> click('Posts'); – sunomad