【发布时间】:2021-12-28 18:42:43
【问题描述】:
目前正在 Lord & Taylor 在线网站上练习运行 TestNG 测试,我遇到了一个问题,即在会话期间,Lord 和 Taylor 的叠加弹出窗口至少在屏幕上弹出一次。大多数时候它出现在主页上,但一旦我点击其中一个部分,它也会出现。我曾尝试使用 xpath,但每次运行浏览器时它似乎都会改变。我也尝试过使用链接文本,但这似乎也不起作用。我可以使用隐式等待并手动单击它,但我觉得必须有一种方法可以用代码来做到这一点。我还遇到了一个问题,有时广告根本无法加载,因此它允许我在它突然弹出之前完成最初的几个测试。它成为我似乎无法克服的障碍。我已经附上了我的代码现在的样子,并且可以真正使用一些帮助来解决这个问题。
package com.LT.Tests;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.LT.Pages.googlePage;
import com.LT.Pages.homePage;
public class homepageTest {
WebDriver driver;
googlePage gp;
homePage hp;
@BeforeTest
public void beforeTest() throws InterruptedException {
System.setProperty("webdriver.chrome.driver","/Users/nezamseraj/Desktop/WSA/Drivers/chromedriver 5");
driver = new ChromeDriver();
hp = new homePage(driver);
gp = new googlePage(driver);
driver.manage().deleteAllCookies();
Thread.sleep(2000);
driver.get("https://www.google.com/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@AfterTest
public void afterTest() {
driver.quit();
}
@Test
public void gpValidation() {
boolean searchbar = gp.searchBar().isEnabled();
boolean searchbutton = gp.searchbutton().isEnabled();
Assert.assertTrue(searchbar);
Assert.assertTrue(searchbutton);
}
@Test(priority = 2)
public void searchLT() {
gp.searchBar().sendKeys("Lord and Taylor");
gp.searchbutton().click();
gp.ltLink().click();
}
@Test(priority = 3)
public void dismissAD() {
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("DECLINE OFFER")));
hp.declineOffer().click();
}
@Test(priority = 3)
public void hpValidation() {
boolean ws = hp.womenSection().isEnabled();
boolean ds = hp.designerSection().isEnabled();
boolean as = hp.accessoriesSection().isEnabled();
Assert.assertTrue(ws);
Assert.assertTrue(ds);
Assert.assertTrue(as);
}
}
【问题讨论】:
标签: java selenium selenium-webdriver testng