Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

crossbrowsertesting/selenium-Junit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Getting Started with Junit and CrossBrowserTesting in Eclipse

For this document, we provide an example test located in our JUnit Github Repository.

JUnit is a Java unit testing framework that is useful for creating scalable and repeatable tests. Eclipse is a widely used Java integrated development environment (IDE) containing a comprehensive workspace for user's code development needs.

In this guide we will use JUnit with Eclipse for testing using the Selenium Webdriver and Java programming language.

Setting up Eclipse

  1. Download and install Eclipse IDE for Java Developers
  2. After installing is complete, launch Eclipse
  3. Select Create a new Java project 

Running a test

You’ll need to use your Username and Authkey to run your tests on CrossBrowserTesting. To get yours, sign up for a free trial or purchase a plan.
  1. Download Selenium WebDriver for Java
  2. Add the Selenium jars to the build path of your project
    • Right click your project folder and select Properties
    • From the Java Build Path tab, select the Libraries tab
    • Select Add External JARs and add all jars for Selenium
    • Apply and Close
  3. Create a new JUnit Test Case
    • Right click your project folder
    • Hover over New and select JUnit Test Case
    • Name your test case and select Finish
    • Select OK to add JUnit to the build path
  4. Copying the following content:
    import static org.junit.jupiter.api.Assertions.*;
    import org.junit.jupiter.api.AfterEach;
    import org.junit.jupiter.api.BeforeEach;
    import org.junit.jupiter.api.Test;
    import org.openqa.selenium.*;
    import org.openqa.selenium.remote.*;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;
    

    class BasicExample {

      private WebDriver driver;
    
        @BeforeEach
        void setUp() throws Exception {
            String username = "YOUR_USERNAME";
            String authkey = "YOUR_AUTHKEY";
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("version", "76");
            capabilities.setCapability("platform", "WINDOWS");
            capabilities.setCapability("name", "Junit Example");
            capabilities.setCapability("browserName", "Chrome");
            capabilities.setCapability("record_video", true);
    
            String hubAddress = String.format("http://%s:%[email protected]:80/wd/hub", username, authkey);
            URL url = new URL(hubAddress);
    
            driver = new RemoteWebDriver(url, capabilities); 
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        
        }
    
        @AfterEach
        void tearDown() throws Exception {
            driver.quit();
        
        }
    
        @Test
        void test() {
            
            driver.get("http://crossbrowsertesting.github.io/selenium_example_page.html");
            assertEquals("Selenium Test Example Page", driver.getTitle());
        
        }
    

    }

  5. Run your test by selecting the Run button

Congratulations! You have successfully integrated CBT and JUnit using Eclipse. Now you are ready to see your build start to run in the Crossbrowsertesting app.

Conclusions

By following the steps outlined in this guide, you are now able to seamlessly integrate JUnit and CrossBrowserTesting. If you have any questions or concerns, please feel free to reach out to our support team.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages