使用Selenium项目执行Squash TA时出错

时间:2016-08-10 15:38:31

标签: selenium automated-tests

我正盯着Squash TA和Seleninum,我遵循教程https://sites.google.com/a/henix.fr/wiki-squash-ta/tutorials/tuto-3-how-to-test-a-web-application-with-database-checks-with-squash-ta-and-selenium//

但我收到了错误

[WARNING] Applied Maven 3.3.x fix
[INFO] Squash TA : compiling tests...
[INFO] Squash TA : initializing context...
[INFO] Listing sqhashTA engine component packages
[INFO] Loading plugin configuration for: org.squashtest.ta.enginecore
[INFO] Loading plugin configuration for: org.squashtest.ta.plugin.commons-component
[INFO] Loading plugin configuration for: org.squashtest.ta.plugin.filechecker
[INFO] Loading plugin configuration for: org.squashtest.ta.plugin.sahi
[INFO] Loading plugin configuration for: org.squashtest.ta.plugin.soapui
[INFO] Loading plugin configuration for: org.squashtest.ta.plugin.selenium
[INFO] Loading plugin configuration for: org.squashtest.ta.plugin.ftp
[INFO] Loading plugin configuration for: org.squashtest.ta.plugin.db
[INFO] Loading plugin configuration for: org.squashtest.ta.plugin.ssh
[INFO] Loading plugin configuration for: org.squashtest.ta.plugin.local.process
août 10, 2016 3:31:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFOS: Loading XML bean definitions from Byte array resource [Computed squashTA engine configuration]
août 10, 2016 3:31:52 PM org.springframework.context.support.GenericXmlApplicationContext prepareRefresh
INFOS: Refreshing org.springframework.context.support.GenericXmlApplicationContext@6e0f7aad: startup date [Wed Aug 10 15:31:52 WAT 2016]; root of context hierarchy
août 10, 2016 3:31:52 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
INFOS: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[WARNING] The endpoint URL is set to its default value: "file://dev/null", so the call back is not activated
[INFO] Squash TA : testing...
[INFO] Beginning execution of ecosystem tests
[INFO] Beginning execution of test first-test.ta
[INFO] Beginning execution of test PetStoreSeleniumTest.ta
[ERROR] It must have java sources in a java subdirectory in resources directory
[ERROR] Test Automation Engine error (non SUT) : method 'convert' from engine component of class 'org.squashtest.ta.plugin.commons.converter.FileToJavaCodeBundle' with argument 'org.squashtest.ta.framework.components.FileResource'  has thrown an exception.
org.squashtest.ta.framework.exception.BadDataException: Java code compilation failed:

	at org.squashtest.ta.plugin.commons.converter.FileToJavaCodeBundle.convert(FileToJavaCodeBundle.java:111)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.squashtest.ta.backbone.tools.ReflectionUtils.invoke(ReflectionUtils.java:252)
	at org.squashtest.ta.backbone.engine.wrapper.ResourceConverterHandler.convert(ResourceConverterHandler.java:106)
	at org.squashtest.ta.backbone.engine.instructionrunner.DefaultConvertResourceRunner.applyConverter(DefaultConvertResourceRunner.java:130)
	at org.squashtest.ta.backbone.engine.instructionrunner.DefaultConvertResourceRunner.convertResource(DefaultConvertResourceRunner.java:94)
	at org.squashtest.ta.backbone.engine.instructionrunner.DefaultConvertResourceRunner.doRun(DefaultConvertResourceRunner.java:54)
	at org.squashtest.ta.backbone.engine.instructionrunner.AbstractDefaultInstructionRunner.run(AbstractDefaultInstructionRunner.java:69)
	at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runInstruction(TestRunnerImpl.java:203)
	at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runInstructionList(TestRunnerImpl.java:148)
	at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runMetaInstruction(TestRunnerImpl.java:172)
	at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runInstructionList(TestRunnerImpl.java:146)
	at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runPhase(TestRunnerImpl.java:136)
	at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runTest(TestRunnerImpl.java:107)
	at org.squashtest.ta.backbone.engine.impl.EcosystemRunnerImpl.runAllTests(EcosystemRunnerImpl.java:202)
	at org.squashtest.ta.backbone.engine.impl.EcosystemRunnerImpl.run(EcosystemRunnerImpl.java:104)
	at org.squashtest.ta.backbone.engine.impl.SuiteRunnerImpl.execute(SuiteRunnerImpl.java:68)
	at org.squashtest.ta.backbone.engine.impl.EngineImpl.execute(EngineImpl.java:63)
	at org.squashtest.ta.maven.SquashTAMojo.executeImpl(SquashTAMojo.java:367)
	at org.squashtest.ta.maven.AbstractSquashTaMojo.execution(AbstractSquashTaMojo.java:85)
	at org.squashtest.ta.maven.AbstractBaseSquashTaMojo.execute(AbstractBaseSquashTaMojo.java:147)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR] The execution raised an error in the TEST phase of the TA script 'PetStoreSeleniumTest.ta' with the message: 'Test Automation Engine error (non SUT) : method 'convert' from engine component of class 'org.squashtest.ta.plugin.commons.converter.FileToJavaCodeBundle' with argument 'org.squashtest.ta.framework.components.FileResource'  has thrown an exception.'.
[INFO] Exporting results
[INFO] Cleaning resources
[INFO] Squash TA : build complete.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.134 s
[INFO] Finished at: 2016-08-10T15:31:54+01:00
[INFO] Final Memory: 22M/182M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.squashtest.ta:squash-ta-maven-plugin:1.9.0-RELEASE:run (default-cli) on project tutorial3-petshop: Build failure : there are tests failures
[ERROR] Test statistics : 2 test runs, 1 passed, 1 tests didn't pass
[ERROR] Tests failed / crashed :
[ERROR] -----------
[ERROR] tests:
[ERROR] ==> PetStoreSeleniumTest.ta
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我的PetStoreSeleniumTest.ta就像:`SETUP:

TEST:

EXECUTE_SELENIUM2 selenium with MAIN CLASS PetStoreSeleniumTest

TEARDOWN:`

我的PetStoreSeleniumTest就像

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class PetStoreSeleniumTest {
    private FirefoxBinary binary = new FirefoxBinary(new File("C:/squash-TA/Firefox12/Firefox Setup 12.0.exe"));
    private FirefoxProfile profile = new FirefoxProfile();
    private WebDriver driver
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setUp() throws Exception {
        driver = new FirefoxDriver(binary,profile);
        baseUrl = "http://localhost:8080/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        system.out.println('test');
    }

    @Test
    public void testPetStoreSelenium() throws Exception {
        driver.get(baseUrl);
        driver.findElement(By.linkText("Enter the Store")).click();
        driver.findElement(By.xpath("//center/a[3]/img")).click();
        driver.findElement(By.xpath("//tr[3]/td/b/a/font")).click();
        driver.findElement(By.xpath("//td[5]/a/img")).click();
        driver.findElement(By.xpath("//td[2]/center/a/img")).click();
        driver.findElement(By.xpath("//center[2]/a/img")).click();
        driver.findElement(By.name("username")).clear();
        driver.findElement(By.name("username")).sendKeys("j2ee");
        driver.findElement(By.name("password")).clear();
        driver.findElement(By.name("password")).sendKeys("j2ee");
        driver.findElement(By.name("update")).click();
        driver.findElement(By.cssSelector("p > input[type=\"image\"]")).click();
        driver.findElement(By.xpath("//center[3]/a/img")).click();
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }

    private boolean isElementPresent(By by) {
        try {
            driver.findElement(by);
            return true;
        } catch (NoSuchElementException e) {
            return false;
        }
    }

    private boolean isAlertPresent() {
        try {
            driver.switchTo().alert();
            return true;
        } catch (NoAlertPresentException e) {
            return false;
        }
    }

    private String closeAlertAndGetItsText() {
        try {
            Alert alert = driver.switchTo().alert();
            String alertText = alert.getText();
            if (acceptNextAlert) {
                alert.accept();
            } else {
                alert.dismiss();
            }
            return alertText;
        } finally {
            acceptNextAlert = true;
        }
    }
}

我在Squash TA论坛上找到了帖子,但它没有解决我的问题。

任何帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

我曾经得到同样的错误,我通过从JDK8切换到JDK7来解决它。目前,Squash TA与JDK8不兼容。
在Eclipse中,右键单击您的项目&gt;以&gt;运行运行配置...... 选择所需的运行配置(例如,“运行选定的测试”),然后转到JRE选项卡并选择JDK7。