Package com.thoughtworks.selenium

Examples of com.thoughtworks.selenium.Selenium

  • link=textPattern: Select the link (anchor) element which contains text matching the specified pattern.
  • css=cssSelectorSyntax: Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.

    Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).

  • Without an explicit locator prefix, Selenium uses the following default strategies:

    Element Filters

    Element filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.

    Filters look much like locators, ie.

    filterType=argument

    Supported element-filters are:

    value=valuePattern

    Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.

    index=index

    Selects a single element based on its position in the list (offset from zero).

    String-match Patterns

    Various Pattern syntaxes are available for matching string values:

    If no pattern prefix is specified, Selenium assumes that it's a "glob" pattern.

    For commands that return multiple values (such as verifySelectOptions), the string being matched is a comma-separated list of the return values, where both commas and backslashes in the values are backslash-escaped. When providing a pattern, the optional matching syntax (i.e. glob, regexp, etc.) is specified once, as usual, at the beginning of the pattern.


            maxWaitTimeInMs = p.getProperty( "MAX_WAIT_TIME_IN_MS" );

            String seleniumHost = p.getProperty( "SELENIUM_HOST" );
            int seleniumPort = Integer.parseInt( ( p.getProperty( "SELENIUM_PORT" ) ) );
            String seleniumBrowser = p.getProperty( "SELENIUM_BROWSER" );
            final Selenium s = new DefaultSelenium( seleniumHost, seleniumPort, seleniumBrowser, baseUrl );
            selenium = new ThreadLocal<Selenium>() {
                protected Selenium initialValue() {
                    return s;
                }
            };
    View Full Code Here


            final ErrorReporterImpl errorReporter = new ErrorReporterImpl(httpCommandProcessor, testContext);

            ErrorReportingCommandProcessor commandProcessor = new ErrorReportingCommandProcessor(httpCommandProcessor,
                    errorReporter);

            final Selenium selenium = new DefaultSelenium(commandProcessor);

            selenium.start();

            testContext.setAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE, baseURL);
            testContext.setAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE, selenium);
            testContext.setAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE, errorReporter);
            testContext.setAttribute(TapestryTestConstants.COMMAND_PROCESSOR_ATTRIBUTE, commandProcessor);

            testContext.setAttribute(TapestryTestConstants.SHUTDOWN_ATTRIBUTE, new Runnable()
            {
                public void run()
                {
                    try
                    {
                        selenium.stop();
                        seleniumServer.stop();
                        stopWebServer.run();

                        // Output, at the end of the Test, any html capture or screen shots (this makes it much easier
                        // to locate them at the end of the run; there's such a variance on where they end up based
    View Full Code Here

            captureScreenshotAndSource( tr.getTestClass().getName(), tr.getThrowable() );
        }

        private static void captureScreenshotAndSource( String cName, Throwable throwable )
        {
            Selenium selenium = AbstractSeleniumTest.getSelenium();
            String locator = "link=Show/hide Stack Trace";
            if ( selenium.isElementPresent( locator ) )
            {
                selenium.click( locator );
            }

            SimpleDateFormat sdf = new SimpleDateFormat( "yyyy.MM.dd-HH_mm_ss" );
            String time = sdf.format( new Date() );
            File targetPath = new File( "target", "screenshots" );
            StackTraceElement stackTrace[] = throwable.getStackTrace();
            int index = getStackTraceIndexOfCallingClass( cName, stackTrace );
            String methodName = stackTrace[index].getMethodName();
            int lNumber = stackTrace[index].getLineNumber();
            String lineNumber = Integer.toString( lNumber );
            String className = cName.substring( cName.lastIndexOf( '.' ) + 1 );
            targetPath.mkdirs();
            String fileBaseName = methodName + "_" + className + ".java_" + lineNumber + "-" + time;
            try
            {
                selenium.windowMaximize();
                File fileName = getFileName( targetPath, fileBaseName, ".png" );
                selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "" );
            }
            catch ( RuntimeException e )
            {
                System.out.println( "Error when take screenshot of error: " + e.getMessage() );
            }
            try
            {
                File fileName = getFileName( targetPath, fileBaseName, ".html" );
                FileUtils.writeStringToFile( fileName, selenium.getHtmlSource() );
            }
            catch ( IOException ioe )
            {
                System.out.println( "Error writing HTML of error: " + ioe.getMessage() );
            }
    View Full Code Here

            final ErrorReporterImpl errorReporter = new ErrorReporterImpl(httpCommandProcessor, testContext);

            ErrorReportingCommandProcessor commandProcessor = new ErrorReportingCommandProcessor(httpCommandProcessor,
                    errorReporter);

            final Selenium selenium = new DefaultSelenium(commandProcessor);

            selenium.start();

            testContext.setAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE, baseURL);
            testContext.setAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE, selenium);
            testContext.setAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE, errorReporter);
            testContext.setAttribute(TapestryTestConstants.COMMAND_PROCESSOR_ATTRIBUTE, commandProcessor);

            testContext.setAttribute(TapestryTestConstants.SHUTDOWN_ATTRIBUTE, new Runnable()
            {
                public void run()
                {
                    try
                    {
                        selenium.stop();
                        seleniumServer.stop();
                        stopWebServer.run();

                        // Output, at the end of the Test, any html capture or screen shots (this makes it much easier
                        // to locate them at the end of the run; there's such a variance on where they end up based
    View Full Code Here

            final ErrorReporterImpl errorReporter = new ErrorReporterImpl(httpCommandProcessor, testContext);

            ErrorReportingCommandProcessor commandProcessor = new ErrorReportingCommandProcessor(httpCommandProcessor,
                    errorReporter);

            final Selenium selenium = new DefaultSelenium(commandProcessor);

            selenium.start();

            testContext.setAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE, baseURL);
            testContext.setAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE, selenium);
            testContext.setAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE, errorReporter);
            testContext.setAttribute(TapestryTestConstants.COMMAND_PROCESSOR_ATTRIBUTE, commandProcessor);

            testContext.setAttribute(TapestryTestConstants.SHUTDOWN_ATTRIBUTE, new Runnable()
            {
                @Override
                public void run()
                {
                    try
                    {
                        LOGGER.info("Shutting down selenium client ...");

                        try
                        {
                            selenium.stop();
                        } catch (RuntimeException e)
                        {
                            LOGGER.error("Selenium client shutdown failure.", e);
                        }
    View Full Code Here

            String methodName = stackTrace[index].getMethodName();
            int lNumber = stackTrace[index].getLineNumber();
            String lineNumber = Integer.toString( lNumber );
            String className = cName.substring( cName.lastIndexOf( '.' ) + 1 );
            targetPath.mkdirs();
            Selenium selenium = AbstractSeleniumTest.getSelenium();
            String fileBaseName = methodName + "_" + className + ".java_" + lineNumber + "-" + time;
            try
            {
                selenium.windowMaximize();
                File fileName = new File( targetPath, fileBaseName + ".png" );
                selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "background=#FFFFFF" );
            }
            catch ( RuntimeException e )
            {
                System.out.println( "Error when take screenshot for test " + tr.getName() + ": " + e.getMessage() );
            }
            try
            {
                File fileName = new File( targetPath, fileBaseName + ".html" );
                FileUtils.writeStringToFile( fileName, selenium.getHtmlSource() );
            }
            catch ( IOException ioe )
            {
                System.out.println( ioe.getMessage() );
            }
    View Full Code Here

            captureScreenshotAndSource( tr.getTestClass().getName(), tr.getThrowable() );
        }

        public static void captureScreenshotAndSource( String cName, Throwable throwable )
        {
            Selenium selenium = AbstractSeleniumTest.getSelenium();
            if ( selenium == null )
            {
                // avoid swallowing exception
                System.err.println( "Not capturing screenshot as Selenium is not initialised" );
                return;
            }

            String locator = "link=Show/hide Stack Trace";
            if ( selenium.isElementPresent( locator ) )
            {
                selenium.click( locator );
            }

            SimpleDateFormat sdf = new SimpleDateFormat( "yyyy.MM.dd-HH_mm_ss" );
            String time = sdf.format( new Date() );
            File targetPath = new File( "target", "screenshots" );
            StackTraceElement trace = getStackTraceOfCallingClass( cName, throwable.getStackTrace() );
            String methodName;
            int lNumber;
            if ( trace == null )
            {
                System.err.println( "Unable to determine the calling method from class " + cName );
                throwable.printStackTrace();
                methodName = "unknown";
                lNumber = 0;
            }
            else
            {
                methodName = trace.getMethodName();
                lNumber = trace.getLineNumber();
            }
            String lineNumber = Integer.toString( lNumber );
            String className = cName.substring( cName.lastIndexOf( '.' ) + 1 );
            if ( !targetPath.exists() && !targetPath.mkdirs() )
            {
                System.out.println( "Unable to create screenshots directory" );
                return;
            }
            String fileBaseName = methodName + "_" + className + ".java_" + lineNumber + "-" + time;

            System.out.println( "Capturing screenshot at " + fileBaseName + ".png" );

            try
            {
                selenium.windowMaximize();
                File fileName = getFileName( targetPath, fileBaseName, ".png" );
                selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "" );
            }
            catch ( RuntimeException e )
            {
                System.out.println( "Error when take screenshot of error: " + e.getMessage() );
            }
            try
            {
                File fileName = getFileName( targetPath, fileBaseName, ".html" );
                FileUtils.writeStringToFile( fileName, selenium.getHtmlSource() );
            }
            catch ( IOException ioe )
            {
                System.out.println( "Error writing HTML of error: " + ioe.getMessage() );
            }
    View Full Code Here

                    break;
                }
            }

            targetPath.mkdirs();
            Selenium selenium = getSelenium();
            String fileBaseName = methodName + "_" + className + ".java_" + lineNumber + "-" + time;

            selenium.windowMaximize();
           
            try
            {
                // save html to have a minimum feedback if jenkins firefox not up
                File fileNameHTML = new File( new File( "target", "errorshtmlsnap" ) , fileBaseName + ".html" );
                FileUtils.writeStringToFile( fileNameHTML, selenium.getHtmlSource() );
            }
            catch ( IOException e )
            {
                System.out.print( e.getMessage() );
                e.printStackTrace();
            }
           
            File fileName = new File( targetPath, fileBaseName + ".png" );

            selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "background=#FFFFFF" );
           
            return fileName.getAbsolutePath();
        }
    View Full Code Here

            if ( StringUtils.isEmpty( seleniumBrowser ) )
            {
                seleniumBrowser = p.getProperty( "SELENIUM_BROWSER" );
            }

          final Selenium s = new DefaultSelenium( seleniumHost, seleniumPort, seleniumBrowser, baseUrl );
          selenium = new ThreadLocal<Selenium>()
          {
              protected Selenium initialValue()
              {
                  return s;
    View Full Code Here

            final ErrorReporterImpl errorReporter = new ErrorReporterImpl(httpCommandProcessor, testContext);

            ErrorReportingCommandProcessor commandProcessor = new ErrorReportingCommandProcessor(httpCommandProcessor,
                    errorReporter);

            final Selenium selenium = new DefaultSelenium(commandProcessor);

            selenium.start();

            testContext.setAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE, baseURL);
            testContext.setAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE, selenium);
            testContext.setAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE, errorReporter);
            testContext.setAttribute(TapestryTestConstants.COMMAND_PROCESSOR_ATTRIBUTE, commandProcessor);

            testContext.setAttribute(TapestryTestConstants.SHUTDOWN_ATTRIBUTE, new Runnable()
            {
                public void run()
                {
                    try
                    {
                        LOGGER.info("Shutting down selenium client ...");

                        try
                        {
                            selenium.stop();
                        } catch (RuntimeException e)
                        {
                            LOGGER.error("Selenium client shutdown failure.", e);
                        }
    View Full Code Here

    TOP

    Related Classes of com.thoughtworks.selenium.Selenium

    Copyright © 2018 www.massapicom. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.