如何配置混合测试自动化框架,将配置从excel工作表传递到从xml文件加载该配置的数据?
我在理解maven项目的自动化测试框架(机密)时有很多困惑。下面是我自己模拟的项目结构的场景 它是一个基于TestNG的框架,还使用了spring的页面对象模型。eclipse如何配置混合测试自动化框架,将配置从excel工作表传递到从xml文件加载该配置的数据?,xml,automated-tests,testng,pageobjects,Xml,Automated Tests,Testng,Pageobjects,我在理解maven项目的自动化测试框架(机密)时有很多困惑。下面是我自己模拟的项目结构的场景 它是一个基于TestNG的框架,还使用了spring的页面对象模型。eclipsefb和fbutil中有两个项目fb处理基于TestNG的执行,使用src/test/java编写的实际测试脚本,测试应用程序的每个页面都有自己的类和套件。在src/test/resources中,我们为它们各自包下的每个类定义了属性文件,还有一个xsd包,其中包含一个pageData.xsd模式,用于pageData.xm
fb
和fbutil
中有两个项目fb
处理基于TestNG的执行,使用src/test/java
编写的实际测试脚本,测试应用程序的每个页面都有自己的类和套件。在src/test/resources
中,我们为它们各自包下的每个类定义了属性文件,还有一个xsd
包,其中包含一个pageData.xsd
模式,用于pageData.xml
pageData.xml
将包含所有带有自定义父标记及其子标记的测试用例的配置。每个父标记将有一个id
,它将对应于data
文件夹中提供的excel表格中的测试用例列,即FbData.xlsx
。子标记也将是一个自定义标记,并将包含在测试用例执行中使用的值
现在,我们将在pageData.xsd
中定义那些在pageData.xml
中使用的自定义标记。这个pageData.xsd
将通过maven为子标记生成getter和setter(我不知道如何生成,但是)。
fbutil
project只是用于excel阅读目的的类(忽略此项)
假设两个测试用例为:
测试用例1:登录和注销
测试用例2:登录并转到配置文件,然后注销
两个测试用例的Excel数据如下所示:
pageData.xml
看起来像:
<configuration id='config1'>
<username>xyz</username>
<password>wxy</password>
</configuration>
xyz
wxy
现在将使用实际测试脚本中的object.getUsername()
和object.getPassword()
调用这些值
我如何理解这些主题以及它们是如何相互作用的?为了深入理解这种设计模式,我应该学习什么?因此,我进行了研究,找到了混合自动化测试框架的这种设计模式的解决方案。也许有人会从中受益 我使用
maven-jaxb2-plugin
从PageData.xml
的模式PageData.xsd
生成类及其getter和setter,该模式为我的测试脚本提供数据。并通过解组xml调用测试类中的getter
Pom.xml
<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.fb.test</groupId>
<artifactId>fb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>fb</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<suiteFile></suiteFile>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.35.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.35.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/test/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/java/${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<!-- jaxb plugin -->
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- the package for the generated java classes -->
<generatePackage>com.fb.test.xsd</generatePackage>
<!-- If the following not specified all xsd in resources are included -->
<schemaDirectory>src/test/resources/xsd</schemaDirectory>
<generateDirectory>${project.basedir}/src/test/generated</generateDirectory>
<generatePackage>com.fb.test.generatedClasses</generatePackage>
<!-- if you don't want old output -->
<removeOldOutput>true</removeOldOutput>
<!-- if you want verbosity -->
<!-- verbose>true</verbose -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<pageData xmlns="http://www.fbtest.com/pageData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="../../src/test/resources/xsd/pageData.xsd ">
<configuration id='config0'>
<username>mno</username>
<password>pqr</password>
</configuration>
<configuration id='config1'>
<username>xyz</username>
<password>wxy</password>
</configuration>
<configuration id='config2'>
<username>abc</username>
<password>def</password>
</configuration>
</pageData>
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com) -->
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.fbtest.com/pageData" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="pageData">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="configuration">
<xs:complexType>
<xs:sequence>
<xs:element name="username" type="xs:string" />
<xs:element name="password" type="xs:string" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
package com.fb.test.profile;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.testng.annotations.Test;
import com.fb.test.generatedClasses.*;
import com.fb.test.generatedClasses.PageData.Configuration;
public class Profile {
@Test
public void f() throws JAXBException, FileNotFoundException {
JAXBContext context = JAXBContext.newInstance("com.fb.test.generatedClasses");
Unmarshaller unmarshler = context.createUnmarshaller();
PageData data = (PageData) unmarshler.unmarshal(new FileInputStream("data/EnvironmentOne/PageData.xml"));
for(Configuration conf: data.getConfiguration()){
System.out.println(conf.getUsername());
System.out.println(conf.getPassword());
}
}
}