Jacobvu84 / selenium-vietnam-training-course

Questions Tracking
7 stars 5 forks source link

Làm thế nào để kiểm thử hướng dữ liệu sử dụng file txt? #18

Closed kimthuy96 closed 6 years ago

kimthuy96 commented 6 years ago

Em có file lazada.txt gồm email, mật khẩu và kết quả mong đợi cách nhau bởi ký tự #: kimthuy@gmail.com#122344#tên đăng nhập hoặc mật khẩu không hợp lệ kimthuy345@gmail.com#1dhfsf#tên đăng nhập hoặc mật khẩu không hợp lệ e muốn xây dựng 1 class riêng để đọc txt để e có thể sử dụng nó đọc nhiều tệp txt khác nhau Sau đó viết class chứa testcase đăng nhập trang lazada sử dụng dữ liệu đã đọc được từ lazada.txt và sendkey dữ liệu đó vào từng trường tương ứng với dữ liệu sau đăng nhập thì e bắt lấy cái message của nó và đi so sánh với cái kết quả mong đợi

Jacobvu84 commented 6 years ago
package com.asksqa.tutorials;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Checking {

    public static void main(String[] args) throws IOException {

        List<AccountLogin> Accounts = new ArrayList<AccountLogin>();

        Accounts = readPlainText("lazada.txt");

        for (AccountLogin account : Accounts) {
            System.out.println("Email: " + account.getEmail()  
                          + " | Password: "+ account.getPwd()
                          + " | Message: "+ account.getErrMsg());
        }
    }

    public static List<AccountLogin> readPlainText(String plainTextFile) {

        String line=null;
        List<AccountLogin> accounts = new ArrayList<AccountLogin>();

        try (BufferedReader br = new BufferedReader(new FileReader(plainTextFile))) {

            while ((line = br.readLine()) != null) {
                String[] items = line.split("#");
                AccountLogin account = new AccountLogin();
                account.setEmail(items[0]);
                account.setPwd(items[1]);
                account.setErrMsg(items[2]);
                accounts.add(account);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return accounts;
    }

}

class AccountLogin{

    private String email;
    private String pwd;
    private String errMsg;

    public void setEmail(String email) { this.email=email; }

    public void setPwd(String pwd) { this.pwd=pwd; }

    public void setErrMsg(String errMsg) { this.errMsg=errMsg; }

    public String getEmail(){ return email; }

    public String getPwd(){ return pwd; }

    public String getErrMsg(){ return errMsg; }

}

@kimthuy96 Đây hi vọng là thứ em cần.