SELENIUM + JAVA and TestNG

Set up môi trường làm việc

The Tool Belt for Selenium Webdriver Tutorial with JAVA and TestNG

Web Automation Framework: Selenium Webdriver

Development Kit: JAVA JDK

Add-On For CSS and XPath Selection: Ranorex Selocity

Test Framework: TestNG (The other popular test runner framework is JUnit)

IDE: IntelliJ Community Edition

Build System: Maven

Environment Editor (Optional): Rapid Environment Editor (RapidEE) [1]

Selenium  + IntelliJ + TestNG + Maven + JAVA JDK

+ Cập nhật thư viện ( dependencies) cần dùng trong pom.xml:

Trong trường hợp này sử dụng TestNG như là Test runner và selenium-java  như là th7 viện selenium ( hoặc dùng thư viện tùy chỉnh khác trong [2])

<dependencies>
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.3</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
</dependencies>

+ Nếu dùng web browser là Chrome:

Cần cài đặt webdriver trước:

[3] https://sites.google.com/a/chromium.org/chromedriver/downloads

Sau đó tạo driver object, và trỏ tới nơi lưu trữ webdriver.

+ Code ví dụ ( Java)

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class Begin {
//We should add @Test annotation that JUnit will run below method
@Test
//Start to write our test method. It should ends with “Test”
public void firefoxTest(){
//Step 1 – Creat driver obj
System.setProperty(“webdriver.chrome.driver”, “C:\\Users\\Downloads\\Software\\chromedriver_win32\\chromedriver.exe”);
WebDriver driver = new ChromeDriver();
//Step 2- Navigation: Open a website
driver.navigate().to(“https://www.google.com/&#8221;);
//Step 3- Assertion: Check its title is correct
//assertEquals method Parameters: Message, Expected Value, Actual Value
Assert.assertEquals(“Google”, “Google”, driver.getTitle());
//Step 4- Close Driver
driver.close();
//Step 5- Quit Driver
driver.quit();
}
}

References:

https://www.seleniumhq.org/

[1] https://www.swtestacademy.com/selenium-webdriver-tutorial-java-testng/

[2] https://www.seleniumhq.org/download/maven.jsp

[3] https://sites.google.com/a/chromium.org/chromedriver/downloads

  • Tạo dự án Selenium trên Intelliji, ngôn ngữ Java

https://saucelabs.com/resources/articles/getting-started-with-webdriver-in-java-using-intellij-on-windows

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s