Udemy - Selenium WebDriver with Java - Basic to Advanced + Frameworks
Section: Framework Building from Scratch - Real Time Project
>cd <eclipse-workspace>
>mvn archetype:generate -DgroupId=Academy -DartifactId=E2EProject -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
>cd <root directory of the new project>
>mvn eclipse:eclipse
- Open Eclipse
- Files ==> Import...
- Select ==> Maven//Existing Maven Project ==> Next
- Maven Projects ==> Browse ==> Project Root Folder ==> Select Folder ==> Finish
- The project will be imported into Eclipse shortly.
- src/test/java - All the test cases created here
- src/main/java - All the utilities, base objects, data and etc.
- pom.xml - the maven configure file
-
Selenium Dependency ==> search "Selenium Maven Information"
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency>
-
TestNG Dependency ==> search "TestNG Maven Dependency"
<dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8</version> <scope>test</scope> </dependency>
-
Save "pom.xml" will get all the dependencies added to the project local repository.
if (browserName == "chrome") - wrong. shouldn't use "==".
extract the value from property file, need use browserName.equalsTo("String");
- == is a reference comparison, i.e. both objects point to the same memory location
- .equals() evaluates to the comparison of values in the objects
- each line ended without semicolon otherwise will cause the problem.
if (browserName == "chrome") - wrong. shouldn't use "==".
extract the value from property file, need use browserName.equalsTo("String");
-
== is a reference comparison, i.e. both objects point to the same memory location
-
.equals() evaluates to the comparison of values in the objects
-
need give the live of driver in LandingPage class
public WebDriver driver; public LandingPage(WebDriver driver) { this.driver = driver; }
- each line ended without semicolon otherwise will cause the problem.
-
Right click the Project-Name ==> TestNG ==> Convert to TestNG
-
"testng.xml" file will be created.
-
Right click "testng.xml" ==> Run As ==> TestNG Suite
-
Running as mvn project from command line
>cd <project root directory> >mvn compile >mvn test
-
Search log4j maven dependency
-
Append the dependency to pom.xml
-
Check if Project//Build Automatically is selected.
-
Add resource folder of "log4j.xml" to "pom.xml" file
src/main/recources true -
Add the source file to java build path - otherwise the system does not know where to find the log4j2.xml configuration file.2
-
right click project ==> Build Path ==> Configure Build Path... ==> Java Build Path//Source Folde
- The 1st and 2nd windows are not closed before the 3rd window opens. They all closed after the tests are completed.
- This is because the TestNG configured the 3 classes inside 1 test.
- Define each class under 1 set of the test to avoid the windows closing issue.
- put "driver = null;" after driver.close(); -- release the memory.
- Change the driver initialize to static that has more advantages.
-
Add Apache commons-io maven dependency to pom.xml
-
Add getScreenshot() method in base class
-
Create a listener class and implements ITestListener
-
Invoke getScreenshot() in Failed Listener.
-
Configure testng.xml - adding the listener.
<listeners> <listener class-name="Academy.Listeners"/> </listeners>
- Get the dependency of "extentreports" and add it to pom.xml
- Get the ExtentReporterNG.java class to be added to the project
- Add ExtentReporterNG as a listener.
- Jenkins installation
- http://localhost:8080/ - Jenkins console
- Jenkins ==> Manage Jenkins ==> Global Tool Configuration
- JDK setup
- GIT setup
- Maven setup
- New Item ==> Enter"E2EProject" ==> General ==> Advanced ==> Use custom workspace
- Build ==> Add build step ==> Invoke top-level Maven targets ==> put the mvn command to the Goals
- Optional - Build Triggers ==> Build periodically
- OOPS Principle Framework
17. Can there be multiple @Test methods in one single class? What changes needed in Testng.xml file to club multiple @Test methods into one single Test Tag.
-
Add the timestamp to the screenshot file.
-
Add the webdrivers to resources folder and change the path to dynamic path