Wilson Mar bio photo

Wilson Mar

Hello. Hire me!

Email me Calendar Skype call 310 320-7878

LinkedIn Twitter Gitter Google+ Youtube

Github Stackoverflow Pinterest

Run browsers automatically for videos (and testing)

Overview

Although Selenium was created for functional testing, I’m using it to repeatedly run through web pages with the timing I want as I record screencast videos.

Install dependencies

Follow my other tutorials to install:

  1. Java
  2. Maven
  3. Firefox browser
  4. Chrome with ChromeDriver
  5. Eclipse IDE (optionally)

Download from GitHub and Run

  1. Change to a folder where you can get a sample repo on your local hard drive.

    This sample doesn’t control an internet browser:

    
    cd ~/gits
    git clone --depth=1 https://github.com/eviltester/startUsingJavaJUnit
    cd startUsingJavaJUnit
    

    --depth=1 specifies no history, since we don’t want to update it, just use the latest version. Thus we save some disk space.

    Cloning into 'startUsingJavaJUnit'...
    remote: Counting objects: 14, done.
    remote: Compressing objects: 100% (8/8), done.
    remote: Total 14 (delta 0), reused 10 (delta 0), pack-reused 0
    Unpacking objects: 100% (14/14), done.
    
  2. Verify if Maven can run:

    mvn test

    If all goes well, you’ll get a lot of outputs ending with something like:

    Running com.javafortesters.junit.MyFirstTest
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.039 sec
     
    Results :
     
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
     
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.010 s
    [INFO] Finished at: 2016-11-21T11:01:56-07:00
    [INFO] Final Memory: 16M/215M
    [INFO] ------------------------------------------------------------------------
    

Selenium frameworks

  1. Import into the IDE from (not https):
    http://www.seleniumhq.org/download/

  2. Scroll to Selenium Standalone Server to click the 3.x version link.

    File selenium-server-standalone-3.0.1.jar was 21.1 MB.

  3. Verify that version is in pom.xml.

Firefox

  1. Download and install Firefox from Mozilla.

  2. See the version by clicking Help > Firefox Health Report. Alternately, click Firefox > About.

    The Version should be 50.0 or above.

  3. If you’re using Selenium 3.0 (which you should), skip the download and install the Gecko driver which Selenium uses.

    https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

IDE

  1. At

    https://www.jetbrains.com/idea/#chooseYourEdition

  2. Scroll down to click “DOWNLOAD” of the .DMG installer for the Community Edition.

    File ideaIC-2016.2.5.dmg was 313 MB, which is version 2016.2.

  3. In Finder at the Downloads folder, click the .dmg file.

  4. Drag the resulting file into your Applications folder.
  5. Dismiss the pop-up.
  6. In Finder, move the .dmg file to trash to save disk space.
  7. In Finder Devices section at the left, eject the IntelliJ IDEA CE installer.
  8. In Finder Applications, scroll to IntelliJ IDEA CE and open it.
  9. Import if you have a previous version installed.

    New project in IntelliJ

  10. Create New Project.
  11. Click New… to the right of Project SDK (Software Development Kit).
  12. Select JDK and press OK to confirm use of:

    /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home

  13. Click Next with “Create project from template” unchecked.
  14. Overtype untitled with a Project name such as “Selenium-3.0.1”.

    PROTIP: Instead of spaces in project names, use dashes or underlines for compound words.

  15. Change the Project location to fit your standards. Click Finish.

    VCS

  16. If you see message “Unregistered VCS root detected”, click the little arrow and select Configure.
  17. Switch temporarily to a Terminal to isssue which git. Copy the response, such as:

    /usr/local/bin/git

  18. Expand Version Control. Click Git. In the “Path to Git executable”, paste the path. Click Test.
  19. Click OK to the “Git executed successfully” pop-up.
  20. Click OK to dismiss the VCS dialog.

    src Selenium class

  21. Alt-click on src, New, Java Class. For Name, use N.N.N.N such as:

    com.jetbloom.Selenium.TestCase01.java

    TODO: Define your naming convention in java programs.

  22. Click OK for a file that makes use of the class name just defined:

    package com.jetbloom.Selenium;
     
    /**
            * Created by mac on 11/21/16.
     */
    public class TestCase01 {
    }
    
  23. Replace the file contents with a sample Selenium Java program:

    package com.jetbloom.Selenium;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
     
    public class TestCase01 {
     public static void main(String[] args){
         WebDriver driver=new FirefoxDriver();
         driver.get("http://learn-automation.com");
         driver.quit();
     }
    }
    

    Maven pom.xml

  24. Alt-click on the module name (in this example, “Selenium-3.0.1”) and select “Add framework support…”.
  25. Check “Maven” then OK. This creates a pom.xml for you to modify.
  26. At the lower-right corner, if there is a message “Maven projects need to be imported”, click “Enable Auto-omport”.

  27. Change the “groupID” to “com.jetbloom.Selenium”.
  28. Copy and paste this before the /project> tag:

     <dependencies>
         <dependency>
             <groupId>org.seleniumhq.selenium</groupId>
             <artifactId>selenium-java</artifactId>
             <version>2.32.0</version>
         </dependency>
    
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.12</version>
         </dependency>
    
     </dependencies>
    
  29. Click Run from the menu or press keys.
  30. Select TestCase01.

  31. In the JRE section, select Use an execution enviornment JRE of “JavaSE-1.8”. Click Next.
  32. In Java Settings, click Libraries tab, Add External JARs. Select the Selenium jar file. Click Open. Click Finish.
  33. In the Package Explorer, select your project,
    expand Reference Libraries to see the Selenium jar.

    Project

Speed measures

sitespeed.io to measure web performance using Selenium as described at https://www.youtube.com/watch?v=cLlZhnZvi1M by Peter Hedenskog
of Wikipedia.

Resources

http://www.guru99.com/selenium-tutorial.html

https://www.youtube.com/watch?annotation_id=annotation_779954917&feature=iv&src_vid=nq97dfaVmC4&v=ff5ZsthcSZw How to Install Java, Maven and IntelliJ on Apple Mac

https://www.youtube.com/watch?annotation_id=annotation_4023503799&feature=iv&src_vid=9IoP45r5Ap4&v=nq97dfaVmC4

https://www.youtube.com/watch?v=rJ4rNZGAzW8 How to start firefox Browser in Selenium webdriver 3 with Gecko Driver by Mukesh Otwani

http://james-willett.com/2015/05/a-gentle-newbie-friendly-guide-to-installing-selenium-webdriver-part-2-get-intellij/