Source:M1.java
1package main;2import org.testng.annotations.Test;3import org.testng.AssertJUnit;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6import org.testng.Assert;7import org.testng.annotations.AfterMethod;8import org.testng.annotations.BeforeMethod;9import org.testng.annotations.Test;10import test.P1;11public class M1 12{13 14 private WebDriver driver;15 @BeforeMethod16 public void beforeMethod()17 {18 System.setProperty("webdriver.chrome.driver", "/Users/madan mohan reddy/Desktop/selenium-java-3.141.59/chromedriver latest");19 driver = (WebDriver) new ChromeDriver();20 driver.manage().window().maximize();21 driver.get("https://testzenlabs.ie/general-information-form/");22 23 24 }25 @Test26 public void generalInformationTest() throws InterruptedException 27 {28 P1.first_name(driver);29 30 AssertJUnit.assertEquals(P1.first_name_Validate(driver), true);31 32 ///validating the text is correct or not33 34 35 P1.Middle_Name(driver);36 37 AssertJUnit.assertEquals(P1.Middle_Name_Validate(driver), true);38 39 ///validating the text is correct or not40 41 P1.Last_Name(driver);42 43 AssertJUnit.assertEquals(P1.Last_Name_Validate(driver), true);44 45 ///validating the text is correct or not46 47 P1.phone_number(driver);48 49 AssertJUnit.assertEquals(P1.phone_number_Validate(driver), true);50 51 ///validating the text is correct or not52 53 P1.Address_One(driver);54 55 AssertJUnit.assertEquals(P1.Address_One_Validate(driver), true);56 57 ///validating the text is correct or not58 59 P1.Address_Two(driver);60 61 AssertJUnit.assertEquals(P1.Address_Two_Validate(driver), true);62 63 ///validating the text is correct or not64 65 P1.pin_code(driver);66 67 AssertJUnit.assertEquals(P1.pin_code_Validate(driver), true);68 69 ///validating the text is correct or not70 71 72 P1.Male(driver);73 74 AssertJUnit.assertEquals(P1.Male_validate(driver), true);75 76 ///validating the text is correct or not77 78 79 P1.Major(driver);80 81 AssertJUnit.assertEquals(P1.Major_validate(driver), true);82 83 ///validating the text is correct or not84 85 P1.Formerly_Registered(driver);86 87 AssertJUnit.assertEquals(P1.Formerly_Registered_validate(driver), true);88 89 ///validating the text is correct or not90 91 P1.continent(driver);92 93 AssertJUnit.assertEquals(P1.continent_Validate(driver), true);94 95 ///validating the text is correct or not96 97 P1.choose_file(driver);98 99 AssertJUnit.assertEquals(P1.choose_file_validate(driver), true);100 101}102 @AfterMethod103 public void afterMethod() 104 {105 driver.quit();106 }107}...
Source:autoResize.java
1package com.psr.TestCases;2import org.testng.annotations.Test;3import org.testng.AssertJUnit;4import org.testng.annotations.Test;5import org.testng.Assert;6import org.testng.AssertJUnit;7import org.testng.annotations.Test;8import org.testng.AssertJUnit;9import java.awt.AWTException;10import java.io.IOException;11import org.testng.annotations.Test;12import com.psr.Locators.Xpath;13import com.psr.PageObject.BaseClass;14import com.psr.PageObject.Library;15import com.psr.Utilities.XLUtils;16/**17* The autoResize program will reSize all 18* PSR columns according to their respective headers values19* 20* @author Shalini21* @version PSR 22*/23public class autoResize extends BaseClass{24 @Test25 public void autoResizeColumns() throws InterruptedException, IOException, AWTException {26 try27 { 28 Library.print("AUTO RESIZE START");29 30 Library.Interaction.wait_ElementToBeVisible(Xpath.ShowAndHide.clickSearch);31 Library.Interaction.click(Xpath.ShowAndHide.clickSearch);32 Library.print("ClickSearch");33 34 Library.Interaction.wait_ElementToBeInVisible(Xpath.loading.loadingIcon);35 36 Library.Interaction.click(Xpath.ReCalc.AutoResize);37 Library.print("ClickAutoResize");38 39 String Expected = XLUtils.jsonRead("Toaster", "AutoResize");40 String Actual = Library.Interaction.ToasterMessage();41 42 if (Library.checkNullOrEmpty(Expected) && Library.checkNullOrEmpty(Actual) && Actual.equalsIgnoreCase(Expected)) {43 AssertJUnit.assertTrue("Success", Actual.equalsIgnoreCase(Expected));44 } else {45 Library.Interaction.captureScreen(driver, "ReCalc");46 AssertJUnit.fail();47 }48 Library.print("AUTO RESIZE END");49 50 }catch(Exception e)51 {52 System.out.println("Error occured...." + e.getMessage());53 Library.Interaction.captureScreen(driver, "ReCalc");54 AssertJUnit.fail();55 }56}57}...
Source:HomepageTests.java
1package in.amazon.tests;2import org.testng.annotations.Test;3import org.testng.AssertJUnit;4import org.testng.annotations.Test;5import org.testng.AssertJUnit;6import org.testng.AssertJUnit;7import org.testng.annotations.Test;8import com.aventstack.extentreports.Status;9import in.amazon.pages.Homepage;10public class HomepageTests extends BaseTest {11 @Test(priority = 0)12 public void verifyTitleOfThePage() throws Exception {13 extentTest = extentReport.createTest("TC -Verify Title of the page ");14 String actualTitle = cmnDriver.getTitle();15 extentTest.log(Status.INFO, "Actual Title: " + actualTitle);16 String expectedTitle = "Amazon Home Page";17 extentTest.log(Status.INFO, "Expected Title: " + expectedTitle);18 AssertJUnit.assertEquals(actualTitle, expectedTitle);19 }20 @Test(priority = 1000)21 public void verifyProductsearch() throws Exception {22 extentTest = extentReport.createTest("TC -Verify Product Search ");23 homepage = new Homepage(driver);24 String product = "Apple Watch";25 String category = "Electronics";26 extentTest.log(Status.INFO, "Product: " + product);27 extentTest.log(Status.INFO, "Category: " + category);28 homepage.searchProduct(product, category);29 }30}...
Source:Asserts.java
1package testRun;2import org.testng.annotations.Test;3import org.testng.AssertJUnit;4import org.testng.annotations.Test;5import org.testng.AssertJUnit;6import org.testng.Assert;7import org.testng.annotations.Test;8import org.testng.asserts.SoftAssert;9public class Asserts {10 /*There r 2 types of assert, it help us to determine the result of the test.11 Hard assert; if we have multiple assert, if the first assert fail, it fails the entire test12 it does not continue.13 Soft assert: however, soft assert continues throughout the test run , before failing the test14 */ 15 @Test16 public void hardAssert() {17 AssertJUnit.assertEquals(2,2);18 AssertJUnit.assertEquals("shoshe","Hurayra");19 AssertJUnit.assertEquals(12,13);20 }21 @Test22 public void softAssert() {23 SoftAssert sa = new SoftAssert();24 AssertJUnit.assertEquals(1,1);25 AssertJUnit.assertEquals("Hurayra","Hurayra");26 AssertJUnit.assertEquals(12, "Hu");27 sa.assertAll();28 //Any time we are using soft assert, we have to finish it by - Assert all()29 }30}...
Source:JunitAssertionTest.java
1package Carlos;2import org.testng.annotations.Test;3import org.testng.AssertJUnit;4import static org.testng.AssertJUnit.assertEquals;5import static org.testng.AssertJUnit.assertTrue;6import org.testng.annotations.Test;7public class JunitAssertionTest {8 @Test9 public void twoPlusTwoEqual4() {10 AssertJUnit.assertEquals(4, 2 + 2);11 }12 @Test13 public void twoPlusTwoEqualFour() {14 AssertJUnit.assertEquals("2 + 2 = 4", 4, 2 + 2);15 }16 boolean result = true;17 @Test18 public void testingAssrtTrue() {19 AssertJUnit.assertTrue(result);20 }21 @Test22 public void testingAssrtTrueWithDescription() {23 AssertJUnit.assertTrue("Result is true ", result);24 }25}...
AssertJUnit
Using AI Code Generation
1public void testAssertJUnit() {2AssertJUnit.assertEquals("TestNG is working fine", "TestNG is working fine");3AssertJUnit.assertTrue(5 > 4);4AssertJUnit.assertFalse(5 < 4);5AssertJUnit.assertNotNull(new Object());6AssertJUnit.assertNull(null);7AssertJUnit.assertNotEquals("TestNG is working fine", "TestNG is not working fine");8AssertJUnit.assertSame(new Integer(5), new Integer(5));9AssertJUnit.assertNotSame(new Integer(5), new Integer(6));10}11public void testAssert() {12Assert.assertEquals("TestNG is working fine", "TestNG is working fine");13Assert.assertTrue(5 > 4);14Assert.assertFalse(5 < 4);15Assert.assertNotNull(new Object());16Assert.assertNull(null);17Assert.assertNotEquals("TestNG is working fine", "TestNG is not working fine");18Assert.assertSame(new Integer(5), new Integer(5));19Assert.assertNotSame(new Integer(5), new Integer(6));20}21public void testAssertJunit() {22org.junit.Assert.assertEquals("TestNG is working fine", "TestNG is working fine");23org.junit.Assert.assertTrue(5 > 4);24org.junit.Assert.assertFalse(5 < 4);25org.junit.Assert.assertNotNull(new Object());26org.junit.Assert.assertNull(null);27org.junit.Assert.assertNotEquals("TestNG is working fine", "TestNG is not working fine");28org.junit.Assert.assertSame(new Integer(5), new Integer(5));29org.junit.Assert.assertNotSame(new Integer(5), new Integer(6));30}31public void testAssertJunitAssert() {32Assert.assertEquals("TestNG is working fine", "TestNG is working fine");33Assert.assertTrue(5 > 4);34Assert.assertFalse(5 < 4);35Assert.assertNotNull(new Object());36Assert.assertNull(null);37Assert.assertNotEquals("TestNG is working fine", "TestNG is not working fine");38Assert.assertSame(new Integer(5), new Integer(5));39Assert.assertNotSame(new Integer(5), new Integer(6));40}41public void testAssertJunitJupiter() {42org.junit.jupiter.api.Assertions.assertEquals("TestNG is working fine", "TestNG is working fine");43org.junit.jupiter.api.Assertions.assertTrue(5 > 4);
1Latency Comparison Numbers (~2012)2----------------------------------3L1 cache reference 0.5 ns4Branch mispredict 5 ns5L2 cache reference 7 ns 14x L1 cache6Mutex lock/unlock 25 ns7Main memory reference 100 ns 20x L2 cache, 200x L1 cache8Compress 1K bytes with Zippy 3,000 ns 3 us9Send 1K bytes over 1 Gbps network 10,000 ns 10 us10Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD11Read 1 MB sequentially from memory 250,000 ns 250 us12Round trip within same datacenter 500,000 ns 500 us13Read 1 MB sequentially from SSD* 1,000,000 ns 1,000 us 1 ms ~1GB/sec SSD, 4X memory14Disk seek 10,000,000 ns 10,000 us 10 ms 20x datacenter roundtrip15Read 1 MB sequentially from disk 20,000,000 ns 20,000 us 20 ms 80x memory, 20X SSD16Send packet CA->Netherlands->CA 150,000,000 ns 150,000 us 150 ms17
TestNG tutorial
TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.
Chapters
- JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
- Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
- Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
- Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
- Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
- Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
- Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
- JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
- Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
- Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
- Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
- DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
- Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
- TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
- TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
- TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
- TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.
Certification
You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.
YouTube
Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.