需要帮助。我有相同的测试套件。我在本地机器上运行了IDEA中的这个测试套件。测试通过了。然后我在TeamCity中运行这个测试套件。下一个堆栈跟踪测试失败:
======= Failed test run #1 ==========
org.openqa.selenium.ElementNotVisibleException: element not visible
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 18 milliseconds
Build info: version: 'unknown', revision: '31c43c8', time: '2016-08-02 21:57:56 -0700'
System info: host: 'build', ip: '175.35.15.235', os.name: 'Windows Server 2012 R2', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=C:\TeamCity\buildAgent\temp\buildTmp\scoped_dir948_4499}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=54.0.2840.71, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: e69e7517d0cc60ff138519603c9efe99
org.openqa.selenium.ElementNotVisibleException:
element not visible
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 18 milliseconds
Build info: version: 'unknown', revision: '31c43c8', time: '2016-08-02 21:57:56 -0700'
System info: host: 'build', ip: '175.35.15.235', os.name: 'Windows Server 2012 R2', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=C:\TeamCity\buildAgent\temp\buildTmp\scoped_dir948_4499}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=54.0.2840.71, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: e69e7517d0cc60ff138519603c9efe99
at com.automation.webdriver.testStoryReportsNavigation.policiesWithPremium(testStoryReportsNavigation.java:122)
这样的122行代码: driver.findElement(By.xpath(" // * [@ id = \" 0 \"]"))click(); (无论是寻找xpath还是id - 在TeamCity中都有相同的结果)
可能是导致此错误的原因是什么? 测试在代理服务于TeamCity的同一台机器上运行。
有一个代码:
package com.automation.webdriver;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.server.handler.CaptureScreenshot;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.ITestResult;
import org.testng.annotations.*;
import pageObjects.homePage;
import utility.Constant;
import utility.ExcelUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class testStoryReportsNavigation {
public WebDriver driver;
private int storyNumber;
private String storyDescription;
@Factory(dataProvider = "dataMethod", dataProviderClass = dataProvider.class)
public testStoryReportsNavigation(int storyNumber, String storyDescription) {
this.storyNumber = storyNumber;
this.storyDescription = storyDescription;
}
@BeforeMethod
public void beforeClass() throws Exception {
System.setProperty(Constant.chromeDriver,Constant.chromeDriverPath);
driver = new ChromeDriver();
ExcelUtils.setExcelFile(Constant.File_userData,"Users");
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get(Constant.devUrl + Constant.loginPage);
WebDriverWait waitLoginPage = new WebDriverWait(driver, 10);
waitLoginPage.until(ExpectedConditions.titleIs("Log in Milliman"));
if (driver.findElements(By.className("glimpse-icon")).size()!=0) {
driver.get(Constant.devUrl + Constant.glimpseSettings);
driver.findElement(By.id("buttonTurnGlimpseOff")).click();
driver.getPageSource().contains("Glimpse cookie set 'Off'");
driver.get(Constant.devUrl + Constant.loginPage);
} else {
System.out.println("Glimpse disabled");
}
WebDriverWait waitLoginPageAgain = new WebDriverWait(driver, 10);
waitLoginPageAgain.until(ExpectedConditions.titleIs("Log in Milliman"));
WebElement eMail = driver.findElement(By.id("Email"));
eMail.sendKeys(ExcelUtils.getCellData(1, 1));
WebElement password = driver.findElement(By.id("Password"));
password.sendKeys(ExcelUtils.getCellData(1, 2));
password.submit();
//Check that Grid View appears after user login:
WebDriverWait wait = new WebDriverWait(driver, 3);
wait.until(ExpectedConditions.urlContains(Constant.gridView));
System.out.println("Login Successful");
//Navigate to Story
System.out.println("Navigating to " + Constant.devUrl + Constant.storyPage + storyNumber + "(" + storyDescription + ")");
driver.get(Constant.devUrl + Constant.storyPage + storyNumber);
WebDriverWait waitLogout = new WebDriverWait(driver, 20);
waitLogout.until(ExpectedConditions.elementToBeClickable(By.className("FiltersShortSummaryBlock")));
//Check that story loaded
driver.findElement(By.className("FiltersShortSummaryBlock")).click();
WebDriverWait waitUrButton = new WebDriverWait(driver, 20);
waitUrButton.until(ExpectedConditions.elementToBeClickable(By.id("UpdateResults")));
//Select Data Source value
driver.findElement(By.xpath("//*[@id=\"PanelGeneral\"]/table/tbody/tr[2]/td[1]/table/tbody/tr[1]/td[2]/button")).click();
WebDriverWait waitDataSource = new WebDriverWait(driver, 10);
waitDataSource.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Market Basket')]")));
driver.findElement(By.xpath("//span[contains(text(), 'Market Basket')]")).click();
//Select Primary Carrier value
driver.findElement(By.xpath("//*[@id=\"PanelGeneral\"]/table/tbody/tr[2]/td[1]/table/tbody/tr[3]/td[2]/button")).click();
driver.findElement(By.xpath("/html/body/div[60]/ul/li[2]/label")).click();
//Select Secondary Carriers value
driver.findElement(By.xpath("//*[@id=\"PanelGeneral\"]/table/tbody/tr[2]/td[1]/table/tbody/tr[4]/td[2]/button")).click();
driver.findElement(By.xpath("/html/body/div[14]/div/ul/li[1]/a/span[2]")).click();
//Click Update Results button
WebDriverWait waitButton = new WebDriverWait(driver, 30);
waitButton.until(ExpectedConditions.elementToBeClickable(By.id("UpdateResults")));
WebElement updateResults = driver.findElement(By.id("UpdateResults"));
updateResults.click();
//Check that Results were updated
WebDriverWait waitUpdateResults = new WebDriverWait(driver, 30);
waitUpdateResults.until(ExpectedConditions.elementToBeClickable(By.id("storyUnsaved")));
}
@Test (priority = 11)
public void policiesWithPremium() throws Exception {
//Generate report #0 and check that it was generated
driver.findElement(By.xpath("//*[@id=\"0\"]")).click();
//Check that report #0 was generated
WebDriverWait waitReportZero = new WebDriverWait(driver, 120);
waitReportZero.until(ExpectedConditions.visibilityOfElementLocated(By.id("RiskWithPremiumForm")));
}