In this article, you will find set up a Selenium Webdriver maven project in Eclipse.
you must assure whether you’ve Maven integration for Eclipse enabled. You can check it by opening the Eclipse marketplace searching for the maven. If it’s not added click to install maven.
in the previous article, we discuss what is testNG and selenium.
Prerequisites
Java
Eclipse
TestNG
how to Install TestNG?
directly from the Eclipse Marketplace.
You can add this plugin from the Eclipse Marketplace.
Step 1: Click on the "Eclipse Marketplace" under "Help" option in the main toolbar
Step 2: After loading marketplace In the "Find" input field type"TestNG" and hit enter.
Step 3: you’ll find an "Install" button then continue installing the TestNG.
then you need Selenium dependencies to run project. This is why you need to build automation tools such as Maven to handle them automatically.because manually handling dependencies can be pretty challenging.
Why We Use Maven?
simply you’ll only need to specify the dependencies in the pom.xml file.
pom.xml ( Project Object Model )
POM XML contains project information and configuration details used by Maven build. It is located in the root directory of each project.
What is Dependency
Any kind of Library which a java project is reliant on, to run or build.
To start the maven project you need to follow below steps.
Step 1: Press "Ctrl + N" to create a new project from the Eclipse IDE.
Step 2: Then hit on Maven > Maven Project and click on Next
Step 3: Tick the "Create a Simple Project (skip archetype selection)" checkbox and click Next.
Step 4: Now you’ll need to type information on the Maven project is created.
Group Id- corresponds to your name or org name
Artefact Id- refers to the project name.
Then hit on the finish button
Step 5: You can now open the pom.xml to view the structure set up by Maven.
Generated project Java code is placed in /src/main/java.
Resources are kept in /src/main/resources
Testing code is placed in /src/test/java
Testing resources are placed in /src/test/resources
To check your browser version
propertyName'
to have the valuepackage Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; import java.util.concurrent.TimeUnit; public class SampleProject { String ChromeDriverLocation = System.getProperty("user.dir")+"\\Driver"+"\\chromedriver.exe"; String URL = "https://techbitezzz.blogspot.com/"; @Test public void OpenChromeDriver() { System.setProperty("webdriver.chrome.driver", ChromeDriverLocation); WebDriver ChromeDriver = new ChromeDriver(); //open browser ChromeDriver.get(URL); //maximize window ChromeDriver.manage().window().maximize(); //wait 60 seconds ChromeDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); //Det page source String Source = ChromeDriver.getPageSource(); //Print System.out.println(Source); //Close Driver ChromeDriver.quit(); } }
No comments:
Post a Comment