簡體   English   中英

為什么我的Selenium測試代碼可以單步成功運行,但是在使用“運行”時卻失敗?

[英]Why my Selenium test code run successfully in single-step but failed when using Run?

我有一些Selenium代碼,可以使用Firefox驅動程序進行一些自動UI測試。 我將它們綁定到一個測試套件中,並有序地運行它們。 但是它在driver.switchTo()。frame()調用上失敗,並拋出org.openqa.selenium.NoSuchFrameException:無法找到frame ,完整的錯誤消息如下:

org.openqa.selenium.NoSuchFrameException: Unable to locate frame: OpenNewPKFD
Command duration or timeout: 3.07 seconds
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'H3000-0254', ip: '169.254.169.127', os.name: 'Windows Vista', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_13'
Session ID: 4fcea4bb-880c-4725-bdf1-cda4b5a03553
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=32.0.3, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]

奇怪的是,如果我以單步模式運行它,則拋出上述異常的代碼行會正常工作。 沒有錯誤發生。 因此,我懷疑是否存在與時間或速度有關的東西,但我根本不知道它是什么。

那么您能給我一些建議來解決這個問題嗎?

下面的更新是我的項目pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>GALSelenium</groupId>
    <artifactId>GALSelenium</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <selenium.version>2.43.1</selenium.version>
    </properties>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>

    </build>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.8</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
</project>

要使用ExpectedConditions,請確保已將它們導入到項目中

org.openqa.selenium.support.ui.ExpectedConditions

Webdriver driver = new FirefoxDriver();
//to wait for an element you need a webdriverWait object
WebDriverWait wait = new WebDriverWait(driver, 15);

element = wait.until(ExpectedConditions.presenseOfElementLocated(By.ID("your_id"));

因此,我想像一下:

frameToSwitchTo = wait.until(ExpectedConditions.presenseOfElementLocated(By.ID("OpenNewPKFD"));
driver.switchTo().frame(frameToSwitchTo);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM