gpt4 book ai didi

java - 只有通过 Jenkins 构建才能找到元素

转载 作者:行者123 更新时间:2023-11-30 08:41:16 28 4
gpt4 key购买 nike

我的自动化测试有问题,我的测试通过 Eclipse 运行没有问题。

但是当我想在 Jenkins 上运行这个测试时,它总是在同一行(在同一个选择器上)失败。

Running TestSuite Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 21173 Only local connections are allowed. Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 34.563 sec <<< FAILURE! - in TestSuite f(webdriver.Single_match_ticket) Time elapsed: 33.86 sec <<< FAILURE! org.openqa.selenium.TimeoutException: Timed out after 19 seconds waiting for element to be clickable: By.cssSelector: a[id='PopularOpener'] > span[tittle='All'] Build info: version: '2.50.1', revision: 'd7fc91b29de65b790abb01f3ac5f7ea2191c88a7', time: '2016-01-29 11:11:26' System info: host: 'Ivan-HP', ip: '192.168.221.103', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Windows\TEMP\scoped_dir676_8604}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=48.0.2564.97, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 634bd38ceca35f9fabe19d967ad5d847 at webdriver.Single_match_ticket.f(Single_match_ticket.java:85)

Results :

Failed tests: Single_match_ticket.f:85 » Timeout Timed out after 19 seconds waiting for elem...

这是我的部分代码:

public void f() throws Exception {

WebDriver driver;
System.setProperty("webdriver.chrome.driver", "webdriver\\chromedriver.exe");



// open Google Chrome




driver = new ChromeDriver();
// Maximize window
driver.manage().window().maximize();
driver.manage().deleteAllCookies();

WebDriverWait wait = new WebDriverWait(driver, 19);

driver.navigate().to("TESTED SITE");


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name='username']")));

// Set values for username and pass
driver.findElement(By.cssSelector("input[name='username']")).sendKeys("1testuser");
driver.findElement(By.cssSelector("input[name='password']")).sendKeys("testtest");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button[type='submit']")));

// Click on LogIn button
driver.findElement(By.cssSelector("button[type='submit']")).click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='userName']")));

String Username = driver.findElement(By.xpath(".//*[@id='userName']")).getText();

String Username1 = "1testuser";

if (!Username1.equals(Username)) {
throw new Exception("You are not logged in");

} else {

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.logout-btn.balance.visible")));
String Balance = driver.findElement(By.cssSelector("div.logout-btn.balance.visible")).getText();

String[] parts = Balance.split("\\.");
String part1 = parts[0];

String secondpart = "";

if (part1.contains(",")) {

secondpart = part1.replace(",", "");
} else {
secondpart = part1;

}

int BalanceInt = Integer.parseInt(secondpart);

if (BalanceInt > 200) {

wait.until(ExpectedConditions
.visibilityOfElementLocated(By.cssSelector("a[id='PopularOpener'] > span[title='All']")));

driver.findElement((By.cssSelector("a[id='PopularOpener'] > span[title='All']"))).click();



for (int i = 0; i < 3; i++) {

最佳答案

此行测试失败:

wait.until(ExpectedConditions
.visibilityOfElementLocated(By.cssSelector("a[id='PopularOpener'] > span[title='All']")));

尽量选择这个元素,而不是像你那样通过css选择

By.cssSelector("a[id='PopularOpener'] > span[title='All']" 

通过其他方式选择它,例如 id、名称、xpath。

关于java - 只有通过 Jenkins 构建才能找到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35174812/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com