`

Selnium -12 How to Use TestNG Framework for Creating Selenium Scripts

 
阅读更多

http://www.softwaretestinghelp.com/testng-framework-selenium-tutorial-12/

 

In the last few tutorials, we shed light on the basic and commonly used WebDriver commands. We also learned about the locating strategies of UI elements and their inclusion in the test scripts. And therefore, we developed our very first WebDriver Automation Test Script.

Moving ahead with this tutorial, we would discuss all about TestNG, its features and its applications.

TestNG is an advance framework designed in a way to leverage the benefits by both the developers and testers. For people already using JUnit, TestNG would seem no different with some advance features. With the commencement of the frameworks, JUnit gained an enormous popularity across the Java applications, Java developers and Java testers, with remarkably increasing the code quality.

Selenium TestNG Framework

See also => JUnit Tutorial and its usage in Selenium scripts

Despite being an easy to use and straightforward framework, JUnit has its own limitations which give rise to the need of bringing TestNG into the picture. TestNG was created by an acclaimed programmer named as “Cedric Beust”. TestNG is an open source framework which is distributed under the Apache software License and is readily available for download.

Talking about our requirement to introduce TestNG with WebDriver is that it provides an efficient and effective test result format that can in turn be shared with the stake holders to have a glimpse on the product’s/application’s health thereby eliminating the drawback of WebDriver’s incapability to generate test reports. TestNG has an inbuilt exception handling mechanism which lets the program to run without terminating unexpectedly.

Both TestNG and JUnit belong to the same family of Unit Frameworks where TestNG is an extended version to JUnit and is more extensively used in the current testing era.

Features of TestNG

  • Support for annotations
  • Support for parameterization
  • Advance execution methodology that do not require test suites to be created
  • Support for Data Driven Testing using Dataproviders
  • Enables user to set execution priorities for the test methods
  • Supports threat safe environment when executing multiple threads
  • Readily supports integration with various tools and plug-ins like build tools (Ant, Maven etc.), Integrated Development Environment (Eclipse).
  • Facilitates user with effective means of Report Generation using ReportNG

TestNG versus JUnit

There are various advantages that make TestNG superior to JUnit. Some of them are:

  • Advance and easy annotations
  • Execution patterns can be set
  • Concurrent execution of test scripts
  • Test case dependencies can be set

Annotations are preceded by a “@” symbol in both TestNG and JUnit.

So now let us get started with the installation and implementation part.

TestNG Installation in Eclipse

Follow the below steps to TestNG Download and installation on eclipse:

Step 1Launch eclipse IDE -> Click on the Help option within the menu -> Select “Eclipse Marketplace..” option within the dropdown.

Selenium TestNG tutorial 1

Step 2: Enter the keyword “TestNG” in the search textbox and click on “Go” button as shown below.

Selenium TestNG tutorial 2

Step 3: As soon as the user clicks on the “Go” button, the results matching to the search string would be displayed. Now user can click on the Install button to install TestNG.

Selenium TestNG tutorial 3

Step 4: As soon as the user clicks on the Install button, the user is prompted with a window to confirm the installation. Click on “Confirm” button.

Selenium TestNG tutorial 4

Step 5: In the next step, the application would prompt you to accept the license and then click on the “Finish” button.

Step 6: The installation is initiated now and the progress can be seen as following:

Selenium TestNG tutorial 5

We are advised to restart our eclipse so as to reflect the changes made.

Upon restart, user can verify the TestNG installation by navigating to “Preferences” from “Window” option in the menu bar. Refer the following figure for the same.

Selenium TestNG tutorial 6

(Click on image to view enlarged)

Selenium TestNG tutorial 7

Creation of Sample TestNG project

Let us begin with the creation of TestNG project in eclipse IDE.

Step 1: Click on the File option within the menu -> Click on New -> Select Java Project.

Selenium TestNG tutorial 8

Step 2: Enter the project name as “DemoTestNG” and click on “Next” button. As a concluding step, click on the “Finish” button and your Java project is ready.

Selenium TestNG tutorial 9

Step 3: The next step is to configure the TestNG library into the newly created Java project. For the same, Click on the “Libraries” tab under Configure Build Path. Click on “Add library” as shown below.

Selenium TestNG tutorial 10

Step 4: The user would be subjected with a dialog box promoting him/her to select the library to be configured. Select TestNG and click on the “Next” button as shown below in the image. In the end, click on the “Finish” button.

Selenium TestNG tutorial 11

The TestNG is now added to the Java project and the required libraries can be seen in the package explorer upon expanding the project.

Selenium TestNG tutorial 12

Add all the downloaded Selenium libraries and jars in the project’s build path as illustrated in the previous tutorial.

Creating TestNG class

Now that we have done all the basic setup to get started with the test script creation using TestNG. Let’s create a sample script using TestNG.

Step 1: Expand the “DemoTestNG” project and traverse to “src” folder. Right click on the “src”package and navigate to New -> Other..

Selenium TestNG tutorial 13

Step 2: Expand TestNG option and select “TestNG” class option and click on the “Next” button.

Selenium TestNG tutorial 14

Step 3: Furnish the required details as following. Specify the Source folder, package name and the TestNG class name and click on the Finish button. As it is evident from the below picture, user can also check various TestNG notations that would be reflected in the test class schema. TestNG annotations would be discussed later in this session.

Selenium TestNG tutorial 15

The above mentioned TestNG class would be created with the default schema.

Selenium TestNG tutorial 16

Now that we have created the basic foundation for the TestNG test script, let us now inject the actual test code. We are using the same code we used in the previous session.

Scenario:

  • Launch the browser and open “gmail.com”.
  • Verify the title of the page and print the verification result.
  • Enter the username and Password.
  • Click on the Sign in button.
  • Close the web browser.

Code:

------------

1 package TestNG;
2 import org.openqa.selenium.By;
3 import org.openqa.selenium.WebDriver;
4 import org.openqa.selenium.WebElement;
5 import org.openqa.selenium.firefox.FirefoxDriver;
6 import org.testng.Assert;
7 import org.testng.annotations.Test;
8  
9 public class DemoTestNG {
10        public WebDriver driver = new FirefoxDriver();
11        String appUrl = "https://accounts.google.com";
12  
13 @Test
14 public void gmailLogin() {
15              // launch the firefox browser and open the application url
16               driver.get("https://gmail.com");
17               
18 // maximize the browser window
19               driver.manage().window().maximize();
20               
21 // declare and initialize the variable to store the expected title of the webpage.
22               String expectedTitle = " Sign in - Google Accounts ";
23               
24 // fetch the title of the web page and save it into a string variable
25               String actualTitle = driver.getTitle();
26               Assert.assertEquals(expectedTitle,actualTitle);
27               
28 // enter a valid username in the email textbox
29               WebElement username = driver.findElement(By.id("Email"));
30               username.clear();
31               username.sendKeys("TestSelenium");
32  
33 // enter a valid password in the password textbox
34               WebElement password = driver.findElement(By.id("Passwd"));
35               password.clear();
36               password.sendKeys("password123");
37               
38 // click on the Sign in button
39               WebElement SignInButton = driver.findElement(By.id("signIn"));
40               SignInButton.click();
41               
42 // close the web browser
43               driver.close();
44 }
45 }

Code Explanation with respect to TestNG

1) @Test – @Test is one of the TestNG annotations. This annotation lets the program execution to know that method annotated as @Test is a test method. To be able to use different TestNG annotations, we need to import the package “import org.testng.annotations.*”.

2) There is no need of main() method while creating test scripts using TestNG. The program execution is done on the basis of annotations.

3) In a statement, we used Assert class while comparing expected and the actual value. Assert class is used to perform various verifications. To be able to use different assertions, we are required to import “import org.testng.Assert”.

Executing the TestNG script

The TestNG test script can be executed in the following way:

=> Right click anywhere inside the class within the editor or the java class within the package explorer, select “Run As” option and click on the “TestNG Test”.

Selenium TestNG tutorial 17

TestNG result is displayed into two windows:

  • Console Window
  • TestNG Result Window

Refer the below screencasts for the result windows:

Selenium TestNG tutorial 18

(Click on image to view enlarged)

Selenium TestNG tutorial 19

HTML Reports

TestNG comes with a great capability of generating user readable and comprehensible HTML reports for the test executions. These reports can be viewed in any of the browser and it can also be viewed using Eclipse’s build –in browser support.

To generate the HTML report, follow the below steps:

Step 1: Execute the newly created TestNG class. Refresh the project containing the TestNG class by right clicking on it and selecting “Refresh” option.

Step 2: A folder named as “test-output” shall be generated in the project at the “src” folder level. Expand the “test-output” folder and open on the “emailable-report.html” file with the Eclipse browser. The HTML file displays the result of the recent execution.

Selenium TestNG tutorial 20

Selenium TestNG tutorial 21

Step 3: The HTML report shall be opened with in the eclipse environment. Refer the below image for the same.

Selenium TestNG tutorial 22

Refresh the page to see the results for fresh executions if any.

Setting Priority in TestNG

Code Snippet

1 package TestNG;
2 import org.testng.annotations.*;
3 public class SettingPriority {
4  
5 @Test(priority=0)
6 public void method1() {
7  }
8  
9 @Test(priority=1)
10 public void method2() {
11  }
12  
13 @Test(priority=2)
14 public void method3() {
15  }
16 }

Code Walkthrough

If a test script is composed of more than one test method, the execution priority and sequence can be set using TestNG annotation “@Test” and by setting a value for the “priority” parameter.

In the above code snippet, all the methods are annotated with the help @Test and the priorities are set to 0, 1 and 2. Thus the order of execution in which the test methods would be executed is:

  • Method1
  • Method2
  • Method3

Support for Annotations

There are number of annotations provided in TestNG and JUnit. The subtle difference is that TestNG provides some more advance annotations to JUnit.

TestNG Annotations:

Following is the list of the most useful and favorable annotations in TestNG:

Annotation Description
@Test The annotation notifies the system that the method annotated as @Test is a test method
@BeforeSuite The annotation notifies the system that the method annotated as @BeforeSuite must be executed before executing the tests in the entire suite
@AfterSuite The annotation notifies the system that the method annotated as @AfterSuite must be executed after executing the tests in the entire suite
@BeforeTest The annotation notifies the system that the method annotated as @BeforeTest must be executed before executing any test method within the same test class
@AfterTest The annotation notifies the system that the method annotated as @AfterTest must be executed after executing any test method within the same test class
@BeforeClass The annotation notifies the system that the method annotated as @BeforeClass must be executed before executing the first test method within the same test class
@AfterClass The annotation notifies the system that the method annotated as @AfterClass must be executed after executing the last test method within the same test class
@BeforeMethod The annotation notifies the system that the method annotated as @BeforeMethod must be executed before executing any and every test method within the same test class
@AfterMethod The annotation notifies the system that the method annotated as @AfterMethod must be executed after executing any and every test method within the same test class
@BeforeGroups The annotation notifies the system that the method annotated as @BeforeGroups is a configuration method that enlists a group and that must be executed before executing the first test method of the group
@AfterGroups The annotation notifies the system that the method annotated as @AfterGroups is a configuration method that enlists a group and that must be executed after executing the last test method of the group

Note: Many of the aforementioned annotations can be exercised in JUnit 3 and JUnit 4 framework also.

Conclusion

Through this tutorial, we tried to make you acquainted with a java based testing framework named as TestNG. We started off the session with the installation of the framework and moved with the script creation and advance topics. We discussed all the annotations provided by TestNG. We implemented and executed our first TestNG test script using annotations and assert statements.

Article summary:

  • TestNG is an advance framework designed in a way to leverage the benefits by both the developers and testers.
  • TestNG is an open source framework which is distributed under the Apache software License and is readily available for download.
  • TestNG is considered to be superior to JUnit because of its advance features.
  • Features of TestNG
    • Support for Annotations
    • Advance execution methodology that do not require test suites to be created
    • Support for parameterization
    • Support for Data Driven Testing using Dataproviders
    • Setting execution priorities for the test methods
    • Supports threat safe environment when executing multiple threads
    • Readily supports integration with various tools and plug-ins like build tools (Ant, Maven etc.), Integrated Development Environment (Eclipse).
    • Facilitates user with effective means of Report Generation using ReportNG
  • Advantages of TestNG over JUnit
    • Added advance and easy annotations
    • Execution patterns can be set
    • Concurrent execution of test scripts
    • Test case dependencies can be set
  • TestNG is freely available and can be easily installed in the Eclipse IDE using Eclipse Market.
  • Upon installation, TestNG would be available as a library within the Eclipse environment.
  • Create a new Java Project and configure the build path using TestNG library.
  • Create a new TestNG class by expanding the created TestNG project and traverse to its “src” folder. Right click on the “src” package and navigate to New -> Other. Select TestNG class option.
  • @Test is one of the annotations provided by TestNG. This annotation lets the program execution to know that method annotated as @Test is a test method. To be able to use different TestNG annotations, we need to import the package “importorg.testng.annotations.*”.
  • There is no need of main() method while creating test scripts using TestNG.
  • We use Assert class while comparing expected and the actual value. Assert class is used to perform various verifications. To be able to use different assertions, we are required to import “import org.testng.Assert”.
  • If a test script is composed of more than one test methods, the execution priority and sequence can be set using TestNG annotation “@Test” and by setting a value for the “priority” parameter.
  • TestNG has a capability of generating human readable test execution reports automatically. These reports can be viewed in any of the browser and it can also be viewed using Eclipse’s built – in browser support.

Next Tutorial #13: Moving ahead with the upcoming tutorials in the Selenium series, we would concentrate on handling the various types of web elements available on the web pages. Therefore, in the next tutorial, we would concentrate our focus on “dropdowns” and will exercise their handling strategies. We would also discuss about WebDriver’s Select class and its methods to select values in the dropdowns.

A remark for the readers: While our next tutorial of the Selenium series is in the processing mode, readers can start creating their own basic WebDriver scripts using TestNG framework.

For more advance scripts and concepts, include as many annotations and assertions in your TestNG classes and execute them using TestNG environment. Also analyze the HTML reports generated by TestNG.

分享到:
评论

相关推荐

    Selenium-Java-Toolkit-Playground:Toolkit演示项目

    【Selenium-Java-Toolkit-Playground:Toolkit演示项目】是一个专门为展示Selenium与Java结合使用的测试工具包而创建的项目。这个项目主要是基于TestNG框架,它为自动化Web应用程序测试提供了一个强大的平台。TestNG...

    selenium3.14-操作参考文档

    ### Selenium 3.14 操作参考文档知识点详解 #### 一、Selenium 简介及背景 Selenium 是一款被广泛采用的开源 Web UI(用户界面)自动化测试工具包,其发展始于 2004 年,由 Jason Huggins 开发并作为 ThoughtWorks ...

    Selenium终极自动化测试环境搭建(二):Selenium+Eclipse+Python .docx

    这是一篇进阶指南,假设读者已经了解Selenium+Eclipse+Junit+TestNG的基本环境搭建,现在将进一步学习如何使用Python进行自动化测试脚本的编写。 #### 二、详细步骤解析 ##### 第一步:安装Python - **下载与安装...

    seleniumE2ELocal

    【标题】"seleniumE2ELocal"是一个与自动化测试相关的项目,主要使用Selenium工具进行端到端(End-to-End,E2E)测试的本地化实施。Selenium是一个广泛使用的开源测试框架,它允许开发人员编写脚本来模拟用户在...

    40nm工艺SNN加速器设计:从RTL到门级电路布局的全流程解析

    内容概要:本文详细介绍了基于40nm工艺的SNN(Spiking Neural Network)加速器的设计与实现全过程。首先从RTL(寄存器传输级)设计入手,展示了神经元模块的基本Verilog代码及其测试平台的构建方法。接着,通过前仿真确保设计的功能正确性,使用VCS工具进行验证。随后进入综合阶段,利用Design Compiler将RTL代码转化为门级网表,并对综合后的设计进行了性能评估。接下来是ICC2布局阶段,通过TCL脚本实现自动化布局,确保物理版图的合理性。最后,通过Makefile整合所有步骤,形成了一套完整的自动化流程。文中还分享了许多实际开发过程中遇到的问题及解决方案,强调了细节处理的重要性。 适合人群:对数字IC设计感兴趣的初学者和技术爱好者,尤其是希望深入了解从RTL到门级电路布局全流程的人群。 使用场景及目标:适用于想要掌握数字IC设计全流程的新手开发者,帮助他们理解并实践从RTL设计到物理版图生成的具体步骤,提高实际动手能力。 其他说明:文章不仅提供了详细的代码示例和技术细节,还分享了作者在实际开发中积累的经验教训,有助于读者避开常见陷阱,提升设计成功率。

    基于双向反激变换器的锂电池组SOC主动均衡控制系统设计与实现

    内容概要:本文详细介绍了基于双向反激变换器的锂电池组SOC主动均衡控制系统的实现过程。首先,文中解释了双向反激变换器的工作原理及其作为能量搬运工具的作用,特别是在SOC过高或过低时的能量转移机制。接着,展示了STM32的PWM配置代码用于驱动MOS管,以及Python仿真的核心算法——平均值-均方差双重判据来决定是否进行均衡。此外,强调了过充过保逻辑的重要性,包括三级保护措施的具体实现。最后,讨论了一些常见的调试陷阱和技术细节,如MOS管驱动不足、变压器漏感等问题,并提供了完整的代码和硬件配置建议。 适合人群:从事锂电池管理系统(BMS)、电力电子、嵌入式系统开发的技术人员,尤其是有一定硬件和软件基础的研发人员。 使用场景及目标:适用于需要对多节锂电池组进行高效、精确SOC均衡控制的应用场合,如电动汽车、储能系统等。主要目标是提高电池组的整体性能和寿命,确保安全运行。 其他说明:文中不仅提供了详细的理论分析和技术实现,还包括了许多实用的经验分享和调试技巧,有助于读者更好地理解和应用这一技术。

    MATLAB增程式电动汽车EREV建模与仿真:从理论到实践详解

    内容概要:本文详细介绍了使用MATLAB进行增程式电动汽车(EREV)建模与仿真的全过程。主要内容涵盖EREV的基本概念、各子系统的建模方法(电池、电机、发动机、离合器)、控制系统的设计以及不同工况下的仿真结果分析。文中不仅提供了具体的MATLAB函数实现,还讨论了建模过程中遇到的问题及其解决方案,如发动机启停优化、电池充放电策略、模式切换逻辑等。通过多个NEDC工况的仿真测试,验证了模型的有效性和优越性能。 适合人群:对新能源汽车技术感兴趣的科研人员、工程技术人员及高校相关专业师生。 使用场景及目标:适用于希望深入了解EREV工作原理和技术实现的研究者;可用于教学演示、技术培训或作为工程项目的基础参考资料。 其他说明:文章强调了MATLAB在新能源车辆建模与仿真中的强大功能,并指出未来可以通过引入机器学习算法进一步提升控制系统的智能化水平。此外,作者分享了许多实用的经验技巧,有助于读者更好地理解和应用所介绍的技术。

    光电信息基础:光电信息基础理论.zip

    光电材料仿真,电子仿真等;从入门到精通教程;含代码案例解析。

    双三相永磁同步电机无模型预测控制:基于扩张状态观测器与虚拟电压矢量的创新应用

    内容概要:本文详细介绍了针对双三相永磁同步电机的一种新型无模型预测控制方法。该方法利用扩张状态观测器(ESO)实时捕捉系统扰动,结合虚拟电压矢量生成技术和占空比优化算法,有效解决了传统控制方法在参数变化和负载突变情况下的不足。主要内容包括:虚拟电压矢量的生成及其对电流谐波的抑制作用;ESO的设计与参数调节,特别是在应对负载突变时的表现;以及占空比优化算法的应用,如黄金分割法和二分法,用于提高系统的响应速度和平滑度。实验结果显示,该方法显著提升了系统的抗干扰能力和控制精度。 适合人群:从事电机控制系统研究与开发的技术人员,尤其是对永磁同步电机控制感兴趣的工程师和研究人员。 使用场景及目标:适用于需要高性能、高可靠性的电机控制系统,如工业自动化设备、家用电器等。主要目标是提高电机控制系统的鲁棒性和效率,减少电流谐波和转矩脉动,增强系统的抗干扰能力。 其他说明:文中提供了详细的算法实现代码和实验数据,有助于读者深入理解和实际应用。此外,文章还讨论了一些实际工程中可能遇到的问题及解决方案,为后续的研究和开发提供了宝贵的实践经验。

    永磁同步电机滑模控制与模型预测转矩控制的Simulink仿真及应用

    内容概要:本文详细介绍了永磁同步电机(PMSM)采用滑模控制(SMC)与模型预测转矩控制(MPTC)相结合的控制策略及其在Simulink中的仿真实现。滑模控制用于转速环,通过设计滑模面和切换增益来提高系统的鲁棒性和抗扰动能力;模型预测转矩控制则应用于转矩环,利用滚动优化和代价函数最小化来实现精确的转矩控制。文中提供了具体的MATLAB代码片段,展示了如何通过调整参数如饱和函数、预测步长和权重系数来优化控制性能。仿真结果显示,在面对转速阶跃和突加负载的情况下,该混合控制策略能够显著降低超调量并提高响应速度。 适合人群:从事电机控制系统研究与开发的技术人员,尤其是对永磁同步电机控制感兴趣的工程师和研究人员。 使用场景及目标:适用于需要高性能、高精度电机控制的应用场合,如工业自动化、电动汽车等领域。目标是通过滑模控制和模型预测转矩控制的结合,实现更好的动态响应和抗扰动性能。 其他说明:文中还提到了一些调试技巧和常见问题,如仿真步长的选择、参数设置的影响以及如何避免常见的错误配置。此外,附带了一份《滑模控制极简指南》,帮助读者更好地理解和应用滑模控制理论。

    ABAQUS中基于CEL算法的高速射流冲击金属板的动力响应模拟及应用

    内容概要:本文介绍了利用ABAQUS软件和CEL(耦合欧拉-拉格朗日)算法进行高速射流冲击金属板的动力响应模拟。CEL算法将计算域分为欧拉网格(用于流体)和拉格朗日网格(用于固体),能够有效地处理流固耦合问题。文中详细描述了材料定义、网格划分、边界条件设置以及接触定义等关键技术环节,并展示了如何通过Python脚本进行后处理分析。特别强调了射流速度、材料参数选择、网格尺寸优化等方面的经验和技巧。实验结果表明,水平速度分量会导致射流在金属板表面形成螺旋状侵蚀轨迹,增加了损伤范围。此外,该模型还可以应用于水下破岩分析等领域。 适合人群:从事流固耦合仿真、材料科学、机械工程等相关领域的研究人员和技术人员。 使用场景及目标:适用于需要模拟高速流体冲击固体结构的动力响应情况,如水下爆破、水力压裂等。主要目标是理解和预测材料在极端条件下的变形和破坏机制。 其他说明:文中提供了详细的代码示例和注意事项,帮助读者更好地理解和应用CEL算法。同时,还分享了一些实践经验,如网格尺寸优化、边界条件设置等,有助于提高仿真的准确性和效率。

    LabVIEW振动与声音分析软件:从信号采集到故障诊断的技术实现

    内容概要:本文详细介绍了使用LabVIEW开发振动与声音分析软件的方法和技术细节。首先,文章讲解了如何通过NI-DAQmx工具包进行振动和声音信号的采集,包括创建任务、配置虚拟通道、设定采样率等步骤。接下来,探讨了时域分析和频域分析的具体实现方式,如计算幅值、使用快速傅里叶变换(FFT)进行频域分析等。此外,还涉及了振动特征提取、声压级计算以及阶次跟踪等功能模块的设计思路。文中不仅提供了详细的代码示例,还分享了一些实用的经验技巧,如选择合适的窗函数、处理高频共振等问题。 适合人群:从事机械设备维护、故障诊断的研究人员和技术人员,尤其是对LabVIEW有一定了解并希望深入掌握其在振动与声音分析方面应用的人群。 使用场景及目标:适用于需要对机械设备进行状态监测和故障预警的企业或研究机构。通过本篇文章的学习,读者可以掌握如何利用LabVIEW搭建完整的振动与声音分析系统,从而有效提升设备管理效率,降低维护成本。 其他说明:文章强调了LabVIEW在信号处理领域的优势,特别是其图形化编程的特点使得复杂算法变得易于理解和实现。同时,文中提到的所有代码均已开源,可供读者下载并应用于实际项目中。

    基于 Global Context Vision Transformers-UNet(GCViT)模型实现的oct黄斑水肿和裂孔完整分割项目、代码、数据、和训练结果、推理结果等

    基于 Global Context Vision Transformers-UNet(GCViT)模型实现的oct黄斑水肿和裂孔完整分割项目、代码、数据、和训练结果、推理结果等 数据集采用【oct黄斑水肿和裂孔,dice约为0.9,训练了300个epoch】,数据在data目录下,划分了训练集和验证集。 【介绍】分割网络为UGlobal Context Vision Transformers-UNet(GCViT),学习率采用cos余弦退火算法。如果想在大尺度进行训练,修改base-size参数即可,优化器采用了AdamW。评估的指标为dice、iou、recall、precision、f1、pixel accuracy等代码会对训练和验证集进行评估。 更多医学图像语义分割实战:https://blog.csdn.net/qq_44886601/category_12816068.html 医学图像改进:https://blog.csdn.net/qq_44886601/category_12858320.html

    故障诊断技术:基于信号处理的故障诊断.zip

    光电材料仿真,电子仿真等;从入门到精通教程;含代码案例解析。

    ABAQUS中基于CEL算法的斜桩锤击入土有限元模拟

    内容概要:本文详细介绍了利用ABAQUS软件及其耦合欧拉-拉格朗日(Coupled Eulerian-Lagrangian, CEL)算法进行斜桩锤击入土过程的有限元模拟。主要内容涵盖地应力平衡设定、锤击荷载施加方式、后处理技术如粒子示踪的应用以及结果分析等方面。文中提供了具体的ABAQUS命令行代码片段,解释了如何配置材料属性、定义荷载工况并提取关键结果数据。此外,作者分享了一些实用的经验和技巧,例如避免常见错误的方法、优化模型稳定性和效率的技术等。 适合人群:从事岩土工程、结构工程及相关领域的研究人员和技术人员,尤其适用于那些希望深入了解ABAQUS软件高级应用的人群。 使用场景及目标:①为科研工作者提供详细的ABAQUS建模指导,帮助他们更好地理解和掌握CEL算法在解决复杂地质问题中的优势;②为企业工程师提供实际工程项目中遇到的具体问题解决方案,提升工作效率和准确性。 其他说明:文章不仅限于理论讲解,还包括大量实例演示和实践经验分享,有助于读者将所学应用于实际工作中。

    电动汽车离线DP节能速度规划与Carsim联合仿真实战

    内容概要:本文详细介绍了电动汽车离线动态规划(DP)节能速度规划算法及其与Carsim联合仿真的具体实现方法。首先,通过Matlab实现DP算法的核心部分,包括状态转移方程、加速度约束、能耗计算等。接着,通过Simulink将DP计算出的速度轨迹输入Carsim进行仿真验证,过程中涉及PID控制器的优化以及各种参数的调整。最后,通过多次实验验证了该系统的有效性,展示了其在不同路况下的节能效果。 适合人群:从事电动汽车控制策略开发的研究人员和技术人员,尤其是对能耗优化感兴趣的开发者。 使用场景及目标:适用于电动汽车的节能优化研究,旨在通过离线DP算法规划最优速度轨迹,并通过Carsim仿真验证其实效性,从而提高车辆的整体能效。 其他说明:文中提到了多个调试经验和常见问题解决方案,如数据同步、PID参数调整等,有助于读者更好地理解和应用该技术。同时,强调了高精地图对于能耗优化的重要性。

    COMSOL中离散裂缝模型在石油工程两相流模拟的应用及优化

    内容概要:本文详细介绍了利用COMSOL进行石油工程中离散裂缝模型(DFM)的两相流(油+水)模拟的方法和技术要点。首先解释了传统双重介质模型的局限性和离散裂缝模型的优势,接着深入探讨了裂缝和基质间的流动方程及其求解方法,如达西定律的修改版、相对渗透率函数的选择以及裂缝-基质交界面上的质量传递条件。文中还分享了具体的建模步骤,包括几何构建、物理场设定、边界条件配置等方面的经验,并强调了后处理过程中的一些实用技巧,如使用探针监测含水率变化、采用自适应网格提高精度等。此外,作者提到了一些常见的陷阱和解决方案,例如避免数值振荡、正确设置α参数等。最后,提供了若干参考文献供进一步研究。 适合人群:从事石油工程领域的研究人员、工程师以及相关专业的高年级本科生和研究生。 使用场景及目标:适用于需要精确模拟复杂地质条件下油水流体行为的研究项目,旨在提升对裂缝系统中流体传输机制的理解,优化油藏管理决策。 其他说明:文中涉及大量MATLAB和COMSOL的具体操作指导,对于希望深入了解并掌握这一先进技术的人来说非常有价值。同时提醒读者关注最新版本的软件特性,以便更好地应用于实际工作中。

    永磁直驱风力发电系统中双PWM变流器控制策略及其MATLAB/Simulink仿真分析

    内容概要:本文详细探讨了永磁直驱风力发电系统(PMSG)中采用的背靠背双PWM变流器控制策略及其在MATLAB/Simulink中的仿真实现。文中介绍了机侧和网侧变流器的双闭环控制策略,包括转速外环、电流内环、电压外环等具体实现方式。此外,文章还讨论了最大功率点跟踪(MPPT)算法的应用,特别是定步长爬山搜索法的具体实现及其优化措施。仿真结果显示,该系统在不同风速条件下均表现出良好的性能,如并网电流谐波含量低、最大功率跟踪效果好等。 适用人群:从事风力发电系统设计、仿真及相关研究的技术人员和研究人员。 使用场景及目标:适用于希望深入了解永磁直驱风力发电系统的工作原理和技术细节的研究人员,以及希望通过仿真验证设计方案的工程师。目标是提高对双PWM变流器控制策略的理解,掌握MPPT算法的实现方法,并能够应用这些知识进行实际项目开发。 其他说明:文章提供了详细的MATLAB代码示例和仿真模型,帮助读者更好地理解和实践相关技术。同时,针对不同电压等级(380V和690V)的系统进行了对比分析,揭示了参数调整的关键点。

    基于PLC1200与Factory IO的虚拟工厂仿真设计及调试经验分享

    内容概要:本文详细介绍了利用西门子TIA Portal V15.1和Factory IO构建虚拟工厂仿真的全过程。首先讲述了环境搭建,包括选择合适的PLC型号(如S7-1200)、正确配置通信参数(如IP地址)以及启用必要的通信权限。接着深入探讨了Factory IO场景的创建,强调了合理的信号映射和物理属性设置对于仿真效果的影响。随后展示了PLC程序的设计思路,特别是状态机的应用和关键逻辑的实现方法。文中还记录了一些常见的调试问题及其解决方案,例如因变量映射错误导致的传送带异常加速现象。最后分享了作者在联机调试过程中积累的经验教训,如使用Ping命令检查网络连通性和调整定时器参数避免误触发等。 适合人群:从事工业自动化领域的工程师和技术爱好者,尤其是对PLC编程和虚拟仿真感兴趣的初学者。 使用场景及目标:帮助读者掌握如何使用TIA Portal和Factory IO进行虚拟工厂仿真系统的搭建与调试,提高编程技能并减少实际项目中的试错成本。 其他说明:文中提供了大量实用的技术细节和实战案例,有助于加深理解和应用。同时提醒读者注意一些容易忽视的小问题,如IP地址配置、变量映射等,这些都是确保系统稳定运行的关键因素。

    工业自动化中基于WINCC的水电气能源报表自动生成与优化

    内容概要:本文详细介绍了在一个工业自动化项目中,利用西门子WINCC平台实现水电气能源消耗数据的自动收集、存储以及生成每日Excel报表的技术方案。主要内容涵盖:使用SQL Anywhere数据库进行数据存储,通过VBScript编写定时任务来捕获实时能耗数据并插入数据库;采用SQL查询语句汇总前一天的数据用于生成报告;借助WINCC内置的Report控件或直接调用Excel应用程序接口完成最终的Excel文件制作。此外,文中还讨论了一些常见的陷阱和技术难点,如确保时间戳一致性、处理文件路径权限问题、避免内存泄漏等。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是那些负责能源管理系统实施和维护的专业人士。 使用场景及目标:适用于需要定期生成能源消耗统计数据的企业,特别是制造业、化工行业等大型工厂。主要目的是提高工作效率,减少人工干预,确保数据准确性,帮助管理层更好地掌握企业的能源使用情况。 其他说明:作者强调了对现有工具特性的深入理解和合理运用的重要性,而不是盲目追求新技术。同时,他还提到可以通过进一步优化(例如引入Python作为中间件)来提升性能。

Global site tag (gtag.js) - Google Analytics