Karate DSL - Test automation framework cho api testing, và có thể là Selenium và appium.

Chuyên mục cung cấp giải pháp kiểm thử tự động và giúp các bạn tìm hiểu sâu hơn về cách viết chương trình kiểm thử cho từng loại dự án riêng của mình.
Forum rules
Chỉ thảo luận các vấn đề liên quan đến kiểm thử tự động
Post Reply
cuhavp
Jr. Tester
Posts: 61
Joined: Mon 21 Jan, 2013 3:52 pm
Contact:

Karate DSL - Test automation framework cho api testing, và có thể là Selenium và appium.

Post by cuhavp »

Karate là một framework còn khá là trẻ (1.5 tuổi), nó ra tạo ra với mục đích là kiểm thử cho api, ít phải lập trình và sử dụng trên nền của cucumber-JVM and gherkin language, Karate hiện nay đã bắt đầu hỗ trợ chạy test với selenium và theo mình có thể sắp tới là appium. Với đà này Karate có thể tiến tới là một framework có thể giúp mọi người làm viêc với api và UI (browser và mobile apps).

Image

Link tham khảo : https://github.com/intuit/karate

Dưới đây là một số ví dụ về cách sử dụng karate :
  • 1. For API test scripts

Code: Select all

@booking
Feature: booking ids
  Return the ids of all the bookings that existing within the API.
  Can take optional query strings to search and return a subset of booking ids.

  Background:
    * url 'http://restful-booker.herokuapp.com'

  Scenario: get all
    Given path 'booking'
    When method get
    Then status 200
    And match each response == { bookingid: '#number'}

  Scenario Outline: filter by name
    Given path 'booking'
    And param 'firstname' = "<name>"
    When method get
    Then status 200
    And match each response == { bookingid: '#number'}
    Examples:
      | name  |
      | sally |
  • 2. For Browser

Code: Select all

Feature: browser automation

  Background:
    * configure driver = { type: 'chrome', executable: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' }
  # * configure driver = { type: 'chromedriver', port: 9515, executable: '/Users/pthomas3/dev/webdriver/chromedriver' }
  # * configure driver = { type: 'geckodriver', port: 4444, executable: '/Users/pthomas3/dev/webdriver/geckodriver' }
  # * configure driver = { type: 'mswebdriver', port: 17556, executable: 'C:/Users/pthomas3/Downloads/MicrosoftWebDriver.exe' }
#   * configure driver = { type: 'safaridriver', port: 4444, executable: 'safaridriver' }

  Scenario: try to login to github and then do a google search

    Given location 'https://github.com/login'
    And input #login_field = 'hello'
    And input #password = 'world'
    When submit //input[@name='commit']
    Then match driver.html('#js-flash-container') contains 'Incorrect username or password.'

    Given location 'https://google.com'
    And input //input[@name='q'] = 'karate dsl'
    When submit //input[@name='btnI']
    Then match driver.location == 'https://github.com/intuit/karate'
    
The pom.xml file :

Code: Select all

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.tvn</groupId>
    <artifactId>rest-api</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.6.0</maven.compiler.version>
        <karate.version>0.9.0.RC4</karate.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-apache</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-junit4</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>3.20.0</version>
        </dependency>
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerArgument>-Werror</compilerArgument>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>



Post Reply

Return to “Automation Framework”