简体   繁体   English

为什么我的Selenium测试代码可以单步成功运行,但是在使用“运行”时却失败?

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

I have some Selenium code which do some automatic UI tests using Firefox driver. 我有一些Selenium代码,可以使用Firefox驱动程序进行一些自动UI测试。 I bind them into a test suite and run them orderly. 我将它们绑定到一个测试套件中,并有序地运行它们。 But it fails on a driver.switchTo().frame() invocation and throws a org.openqa.selenium.NoSuchFrameException: Unable to locate frame , the full error messages are as below: 但是它在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}]

The weird thing is, if I run it in single-step mode, the code line which throws above exception will work just fine. 奇怪的是,如果我以单步模式运行它,则抛出上述异常的代码行会正常工作。 No error occurs. 没有错误发生。 So I suspect there're something related to time or speed, but I don't know what it is at all. 因此,我怀疑是否存在与时间或速度有关的东西,但我根本不知道它是什么。

So can you give me some advice to deal with this problem? 那么您能给我一些建议来解决这个问题吗?

UPDATED below is my pom.xml of the project: 下面的更新是我的项目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>

To use the ExpectedConditions, ensure that you have imported them into your 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"));

As such for you issue, I would imagine something like: 因此,我想像一下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium java 代码成功运行测试,但在无头运行时失败 - Selenium java code runs test successfully but fails when run as headless 无法在Eclipse中成功运行硒测试 - Can't successfully run a selenium test in Eclipse 无法为我的测试用例运行 java junit selenium 代码 - Unable to run java junit selenium code for my test case 使用Selenium WebDriver运行测试 - Run a test using selenium webdriver 如何使用testng并行运行我的硒测试方法 - how to run my selenium test methods in parallel using testng 使用Junit运行硒测试时出现空指针异常 - Null Pointer exception when I run the selenium test using Junit 无法在 vs 代码上运行 selenium 测试 - can't run selenium test on vs code 为什么我的 java docker 图像在笔记本电脑上创建成功,但上传到谷歌云运行时失败? - Why is my java docker image created successfully on laptop but when uploading to google cloud run it fails? 尝试在 Ubuntu 上运行 Selenium 测试时出现问题 - Problem when try to run Selenium Test on Ubuntu 使用runtime.getruntime命令通过Java代码运行时,该命令无法成功执行 - command does not execute successfully when run through java code using runtime.getruntime command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM