Getting Started with Selenium: Set up Selenium-Maven-Java Project in Eclipse
Step by step set up process of test development environment.
Step -1: Download and install Eclipse IDE. Eclipse can be downloaded from here https://www.eclipse.org/downloads/
Step - 2: Then open the Eclipse IDE
Step -3. Create a new project by selecting File >> New >> Project
Step - 4. Then on the new dialog, select Maven >> Maven Project and click Next
Step - 5. Then the new dialog will be displayed. Select the following checkbox as in the screenshot for Create a simple project and you can also select the checkbox for Use default Workspace location. Then click on Next
Step - 6. On the new dialog box, insert the Group Id and Artifact Id as in following screenshot and click Finish button
Step - 7. Your project will be created similar as following screenshot:
Step -8. Select pom.xml from Package Explorer.
Step -9. Add the JUnit, TestNG and Selenium WebDriver dependencies as maven entry in pom.xml file inside the <project></project> tag.
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
Step -10. Eclipse will then download dependencies. To download dependencies you need to enable internet connection on your device. After download completed, there will be a directory there Maven Dependencies inside your project Step - 11. Then you have to create a new class. Select src/test/java in Package Explorer and right click to show the menu. Select New >> Class as shown in the screenshot
Step - 12. Then in following dialog enter the package name and class name as displayed in the following screenshot. Then click Finish button. This will create a class inside your package.
Step -13. Add the following code inside the class you created in step - 12
package gettingStartedWithSelenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.junit.*;
import static org.junit.Assert.*;
public class MyBlogPageLoad {
protected WebDriver driver;
@Before
public void setUp(){
System.setProperty("webdriver.chrome.driver",
"./src/test/resources/chromedriver.exe");
driver = new ChromeDriver(); //Launch Chrome
driver.manage().window().maximize(); //Maximize the browser window
driver.get("https://humayunashik.blogspot.com/");
}
@Test
public void loadMyBlog(){
System.out.println("Inside the function");
new WebDriverWait(driver, 10).until(new ExpectedCondition() {
public Boolean apply(WebDriver d){
System.out.println(d.getTitle());
return d.getTitle().startsWith("Humayun Ahmed Ashik");
}
});
assertEquals("Humayun Ahmed Ashik", driver.getTitle());
}
@After
public void tearDown() throws Exception{
System.out.println("Closing the driver");
driver.quit();
}
}
Step - 14. You need to download chromedriver for running the code. Download it from here: https://chromedriver.chromium.org/downloads. Then extract the zip file and paste the chromedriver.exe file inside into src/test/resources
Step -15. To run the tests, select the project in Project Explorer. Right-click on the project name and select Run As >> JUnit Test as shown in following screenshot:
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন