项目实训三--系统功能测试(二)

题目推荐模块

编号

测试用例描述

输入值

预期结果

实际结果

备注

1

题目输入的长度超过规定需求

失败并提示错误信息失败并提示错误信息

异常情况

2

输入的问题是英语,用英语回答问题

Generate five questions about threads

回答成功

回答成功

正常流程

3

一次性输入题目不止一个问题

生成5个线程的题目?
生成10个计算机网络的选择题

回答成功(两个问题都回答)

回答成功

正常情况

4

输入的都是特殊符号无法解析  

abcdefghi

失败并提示错误信息

失败并提示错误信息

异常情况

5

输入为空

失败并提示错误信息

失败并提示错误信息

异常情况

7

输入了错误的学科词汇

生成10个计算机络网的选择题

回答成功

回答成功

证明大模型有一定的容错性(容错性测试)

8题目不仅要求生成题目还要生成对应答案 解析生成5个线程的题目及其答案回答成功回答成功大模型的应变性很强(应变性测试)

 测试脚本:

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.support.ui.*;

import java.io.File;

public class QuestionSubmissionTests {
    private WebDriver driver;

    @Before
    public void setup() {
        System.setProperty("webdriver.gecko.driver", "D:\\Drivers\\geckodriver.exe");
        File pathBinary = new File("D:\\Firefox\\firefox.exe");
        FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary(firefoxBinary);
        driver = new FirefoxDriver(options);
        driver.manage().window().maximize();
        driver.get("http://your-test-url.com");
    }

    @After
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }

    private void submitQuestion(String question) {
        WebElement questionInput = driver.findElement(By.name("question"));
        WebElement submitButton = driver.findElement(By.name("submit"));

        questionInput.sendKeys(question);
        submitButton.click();
    }

    private WebElement waitForElement(By locator) {
        return new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(locator));
    }

    @Test
    public void testLongQuestionInput() {
        submitQuestion("This is a very long question that exceeds the maximum allowed length for questions in the system...");
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("题目输入的长度超过规定需求"));
    }

    @Test
    public void testEnglishQuestion() {
        submitQuestion("Generate five questions about threads");
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("回答成功"));
    }

    @Test
    public void testMultipleQuestionsInput() {
        submitQuestion("生成5个线程的题目?生成10个计算机网络的选择题");
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("回答成功"));
    }

    @Test
    public void testSpecialCharactersInput() {
        submitQuestion("abcdefghi");
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("输入无法解析"));
    }

    @Test
    public void testEmptyQuestionInput() {
        submitQuestion("");
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("无法提交"));
    }

    @Test
    public void testIncorrectDisciplineTerm() {
        submitQuestion("生成10个计算机络网的选择题");
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("回答成功"));
    }

    @Test
    public void testQuestionWithAnswersAndExplanations() {
        submitQuestion("生成5个线程的题目及其答案");
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("回答成功"));
    }
}

答案测评

编号

测试用例描述

输入值

预期结果

实际结果

备注

1

题目输入的长度超过规定需求

失败并提示错误信息失败并提示错误信息

异常情况

2答案输入的长度超过规定需求失败并提示错误信息失败并提示错误信息异常情况

4

输入的都是特殊符号无法解析  

abcdefghi

失败并提示错误信息

失败并提示错误信息

异常情况

5

答案输入为空

失败并提示错误信息

失败并提示错误信息

异常情况

6题目输入为空失败并提示错误信息失败并提示错误信息异常情况

7

答案中输入了错误的学科词汇

.....

测评中可以发现

测评中可以发现

证明大模型有一定的容错性(容错性测试)

8题目中输入了错误的学科词汇计算机落网的定义测评中可以发现测评中可以发现测评不仅针对答案,也针对题目

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.support.ui.*;

import java.io.File;

public class QuestionAndAnswerSubmissionTests {
    private WebDriver driver;

    @Before
    public void setup() {
        System.setProperty("webdriver.gecko.driver", "D:\\Drivers\\geckodriver.exe");
        File pathBinary = new File("D:\\Firefox\\firefox.exe");
        FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary(firefoxBinary);
        driver = new FirefoxDriver(options);
        driver.manage().window().maximize();
        driver.get("http://your-test-url.com");
    }

    @After
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }

    private void submitQuestionAndAnswer(String question, String answer) {
        WebElement questionInput = driver.findElement(By.name("question"));
        WebElement answerInput = driver.findElement(By.name("answer"));
        WebElement submitButton = driver.findElement(By.name("submit"));

        questionInput.sendKeys(question);
        answerInput.sendKeys(answer);
        submitButton.click();
    }

    private WebElement waitForElement(By locator) {
        return new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(locator));
    }

    @Test
    public void testLongQuestionInput() {
        String longQuestion = "This is a very long question that exceeds the maximum allowed length for questions in the system...";
        String validAnswer = "Valid answer.";
        submitQuestionAndAnswer(longQuestion, validAnswer);
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("题目输入的长度超过规定需求"));
    }

    @Test
    public void testLongAnswerInput() {
        String validQuestion = "Valid question.";
        String longAnswer = "This is a very long answer that exceeds the maximum allowed length for answers in the system...";
        submitQuestionAndAnswer(validQuestion, longAnswer);
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("答案输入的长度超过规定需求"));
    }

    @Test
    public void testSpecialCharactersInput() {
        String specialCharsQuestion = "abcdefghi";
        String specialCharsAnswer = "abcdefghijk";
        submitQuestionAndAnswer(specialCharsQuestion, specialCharsAnswer);
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("无法解析"));
    }

    @Test
    public void testEmptyAnswerInput() {
        String validQuestion = "Valid question.";
        String emptyAnswer = "";
        submitQuestionAndAnswer(validQuestion, emptyAnswer);
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("答案不能为空"));
    }

    @Test
    public void testEmptyQuestionInput() {
        String emptyQuestion = "";
        String validAnswer = "Valid answer.";
        submitQuestionAndAnswer(emptyQuestion, validAnswer);
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("题目不能为空"));
    }

    @Test
    public void testIncorrectDisciplineTermInAnswer() {
        String validQuestion = "Valid question.";
        String incorrectDisciplineAnswer = "计算机络网的定义";
        submitQuestionAndAnswer(validQuestion, incorrectDisciplineAnswer);
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("正确回答"));
    }

    @Test
    public void testIncorrectDisciplineTermInQuestion() {
        String incorrectDisciplineQuestion = "计算机落网的定义";
        String validAnswer = "Valid answer.";
        submitQuestionAndAnswer(incorrectDisciplineQuestion, validAnswer);
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("测评中可以发现"));
    }

    @Test
    public void testQuestionAndAnswerWithIncorrectDisciplineTerms() {
        String incorrectDisciplineQuestion = "计算机落网的定义";
        String incorrectDisciplineAnswer = "计算机网络是指由多个计算机及其他硬件设备通过通信介质相互连接而成的系统,以实现资源共享和信息交换的目的。计算机网络可以分为局域网(Local Area Network, LAN)、广域网(Wide Area Network, WAN)、城域网(Metropolitan Area Network, MAN)和个人区域网(Personal Area Network, PAN)等类型。";
        submitQuestionAndAnswer(incorrectDisciplineQuestion, incorrectDisciplineAnswer);
        WebElement result = waitForElement(By.id("result"));
        Assert.assertTrue(result.getText().contains("测评中可以发现"));
    }
}

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值