Selenide Google 示例项目教程

随笔20小时前发布 就像爱生命
4 0 0

Selenide Google 示例项目教程

googleAutomated tests for Google search项目地址:https://gitcode.com/gh_mirrors/googl/google

1. 项目的目录结构及介绍




google/


├── src/


│   ├── test/


│   │   ├── java/


│   │   │   └── com/


│   │   │       └── example/


│   │   │           └── google/


│   │   │               └── GoogleTest.java


│   ├── main/


│   │   ├── java/


│   │   │   └── com/


│   │   │       └── example/


│   │   │           └── google/


│   │   │               └── GooglePage.java


├── pom.xml


├── README.md

src/test/java/com/example/google/GoogleTest.java: 测试类文件,包含对Google搜索功能的测试。src/main/java/com/example/google/GooglePage.java: 页面类文件,定义了Google搜索页面的元素和操作。pom.xml: Maven项目的配置文件,包含了项目的依赖和插件配置。README.md: 项目说明文件,提供了项目的概述和使用说明。

2. 项目的启动文件介绍

项目的启动文件是 GoogleTest.java,它位于 src/test/java/com/example/google/ 目录下。这个文件包含了使用Selenide进行自动化测试的代码。以下是该文件的简要介绍:




package com.example.google;


 


import com.codeborne.selenide.Configuration;


import org.junit.jupiter.api.BeforeAll;


import org.junit.jupiter.api.Test;


 


import static com.codeborne.selenide.Condition.text;


import static com.codeborne.selenide.Selenide.*;


 


public class GoogleTest {


 


    @BeforeAll


    public static void setup() {


        Configuration.baseUrl = "https://www.google.com";


    }


 


    @Test


    public void userCanSearch() {


        open("/");


        $("#lst-ib").val("Selenide").pressEnter();


        $$("#ires .g").shouldHaveSize(10);


        $("#ires .g").shouldHave(text("Selenide: Concise UI Tests in Java"));


    }


}

@BeforeAll: 在所有测试运行前执行的设置方法,配置了Google的基本URL。@Test: 测试方法,验证用户可以在Google上搜索并找到相关结果。

3. 项目的配置文件介绍

项目的配置文件是 pom.xml,它位于项目根目录下。这个文件包含了Maven项目的配置信息,包括依赖项、插件和项目的基本信息。以下是该文件的简要介绍:




<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.example</groupId>


    <artifactId>google</artifactId>


    <version>1.0-SNAPSHOT</version>


 


    <dependencies>


        <dependency>


            <groupId>com.codeborne</groupId>


            <artifactId>selenide</artifactId>


            <version>5.20.1</version>


        </dependency>


        <dependency>


            <groupId>org.junit.jupiter</groupId>


            <artifactId>junit-jupiter</artifactId>


            <version>5.7.0</version>


            <scope>test</scope>


        </dependency>


    </dependencies>


 


    <build>


        <plugins>


            <plugin>


                <groupId>org.apache.maven.plugins</groupId>


                <artifactId>maven-surefire-plugin</artifactId>


                <version>2.22.2</version>


            </plugin>


        </plugins>


    </build>


</project>

<dependencies>: 定义了项目所需的依赖项,包括Selenide和JUnit。<build>: 定义了项目的构建配置,包括Maven Surefire插件,用于运行测试。

通过

googleAutomated tests for Google search项目地址:https://gitcode.com/gh_mirrors/googl/google

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...