SRP : A class should have one reason to change
LSP : enable to replace objects of a parent class with objects of subclass without breaking the application
ISP : Splitting methods of a contract into groups of responsability and assigning interface to these groups.
DIP: isolate the class from concrete implementation and having them depend on an abstract classes or interfaces.
Selenium is an open source automated testing suite for web applications across different browsers and platforms. => It focuses on automating
Selenium is not just a single tool but a suite of software's, each catering to different testing needs of an organization. It has 4 components:
- Selenium Integrated Development Environment (IDE)
- Selenium Remote Control (RC)
- WebDriver
- Selenium Grid
Selenium Integrated Development Environment (IDE) is the simplest framework in the Selenium suite and is the easiest one to learn. (record)
WebDriver is a web automation framework that allows you to execute your tests against different browsers, WebDriver also enables you to use a programming language in creating your test scripts (not possible in Selenium IDE). It controls the browser from the OS level
WebDriver directly talks to the browser while Selenium RC needs the help of the RC Server in order to do so.
- Open Web Page
driver.get("https://google.com");
driver.navigate().to("http://www.insat.rnu.tn");
- Get URL
driver .getCurrentUrl();
- Get title
driver.getTitle();
- Forward , back , refrech the page
driver.navigate().back();
driver.navigate().forward();
driver.navigate().refresh();
- Switch
driver.switchTo().newWindow(WindowType.WINDOW);
driver.switchTo().newWindow(WindowType.TAB);
- Close
driver.close(); driver.quit();
- Windows management
// Size
driver.manage().getSize().getHeight();
driver.manage().getSize().getWidth();
//Position
driver.manage().setPosition(new Point(0,0));
driver.manage().window().maximize();
driver.manage().window().minimize();
driver.manage().window().fullscreen();
//Screenshots
File screeenshotFile =((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
Selenium grid is a tool used together with Selenium RC to run parallel tests across different machines and different browsers all at the same time. Parallele execution means running multiple test at one
JUnit is an open source framework for the development and execution of automatable unit tests. The main interest is to ensure that the code still meets the needs even after possible modifications. More generally, this type of tests is called unit non-regression tests.
Annotation | Meaning | Usecase |
---|---|---|
@BeforeClass |
Run only once and specifically before anything else is run in the test class | initializes Selenium Webdriver and opens a browser |
@AfterClass |
It is the annotation used to execute tasks after all the tests have been completed | close the browser and free that resource once all tests within the JUnit Selenium test class have been executed |
@BeforeEach |
run code before each test | When writing a Selenium test class, there might be a mandatory step that starts the test from a specific web page. In that case, one can use the @Before annotation so that the required webpage is opened and ready before any test is run. |
@AfterEach |
is used to run tasks after the execution of each test. After every test, the test results might have to be sent to a logging service or a monitoring service. | |
@Test |
identify the actual test case | |
@RepeatedTest |
run a given test any number of times | A web application is built to ensure caching does not occur due to highly dynamic data. So, each time the webpage is loaded, the cache must be empty. To automate the testing of this scenario, one has to run the same sequence multiple times. |
@ParameterizedTest |
Parameterized test is to execute the same test over and over again using different values. | |
Example : |
// tells Selenium to set the timeout to 5 seconds
@Test(timeout=5000)
//@RepeatedTest takes in an integer which tells JUnit to run the test called “test” 6 times.
@RepeatedTest(6)
public void test()
{
// selenium test
}