当前位置:网站首页>How to read excel test data in Go language, easy to learn
How to read excel test data in Go language, easy to learn
2022-07-29 19:32:00 【Rejoice in the testing world】
The data in the test is often saved in Excel, especially the steps and input parameters of some use cases.The advantage of this is that no matter what tool you use, no matter what programming language you use, you can automate testing by reading data in a common format.
In automated testing, the most commonly used programming languages are Python and Java, but with the popularity of golang, more and more technical teams use go language for automated testing.
This article is about how to read test data in excel in go language.
Excelize is a library written in Go language for manipulating Excel documents. Now we use excel files in xlsx format, which can be manipulated through the excelize library.In addition to supporting data manipulation, Excelize can also design styles, action icons, pivot tables and slicers.
open excel
1. Open excel
The advantage of the Go language is that defer can be used to perform some post-operations, and defer can be called at the end of the function execution, so after opening excel, you can directly close the file through defer, and other operations can be written later, so as not to forgetClose the file.

Read sheet
2. Read sheet form
An Excel will contain multiple tables, so you must first select a table to read the content in it. I personally think csv is a more suitable form for storing use case data. Just open the file directly, no need to select againTable, and csv only focuses on data, the operation will be much faster.But now excel is still used more, so I will continue to focus on reading the data, and I will talk about the csv format next time.
rows, err := f.GetRows("Sheet1")if err != nil {log.Fatal("Failed to open the form")}The table gets a nested Slice, and each row of data can be obtained through the for loop:
for _, row := range rows {log.Println(row)}Next iteration
You can also get an iterable object, manually iterate once through Next, and take out the header data of the first row.All data of this row can be obtained through rows.Columns().

The next loop will get all the test data.
for rows.Next() {columns, err := rows.Columns()if err != nil {log.Fatal("Error getting data")}log.Println(columns)}Summary
The first step: read the file through OpenFile
Step 2: Read all row data through GetRows
You can also get the left and right rows through Rows, and then manually iterate to get the data through Next.
Finally: Available on the official account: Sad Spicy Tiao!Get a 216-page software test engineer interview collection document by yourself [free].And the corresponding video learning tutorials are shared for free!, including basic knowledge, Linux essentials, Shell, Internet program principles, Mysql database, packet capture tool topics, interface testing tools, advanced testing-Python programming, Web automated testing, APP automated testing, interface automated testing, testingAdvanced continuous integration, testing architecture development testing framework, performance testing, security testing, etc.
Now I invite you to join our software testing learning exchange group: [746506216], note "join the group", everyone can join togetherDiscuss and communicate software testing, learn software testing techniques, interviews and other aspects of software testing together. There will also be free live classes to gain more testing skills. Let's advance Python automated testing/test development together and move towards a high-paying careerroad.
Friends who like software testing, if my blog is helpful to you, if you like my blog content, please "Like", "Comment" and "Favorite" with one click!
Self-study course for software test engineers:
Interface performance test—software testers must know 618 actual combat scene analysis
Meituan Interview Questions_Advanced Test 25K Job Interview - Software Testers Should See
Jmeter actual combat explanation case - software testers will definitely know

边栏推荐
猜你喜欢
随机推荐
嵌入式开发:嵌入式基础——软件错误分类
centos8安装redis
函数的声明与作用域
PX4模块设计之十四:Event设计
字节跳动 Flink 状态查询实践与优化
已经删除了的SQL节点,有没有办法恢复
MarkBERT
kubernetes之资源限制及QOS服务质量
R语言时间序列数据可视化: 使用plot函数可视化单序列时间序列数据、多序列时间序列数据并指定不同时间序列的线条类型(lty)
Apache Doris 1.1 特性揭秘:Flink 实时写入如何兼顾高吞吐和低延时
593. 有效的正方形 改善丑陋的代码
Neo4j开源NoSQL数据库
R语言时间序列数据提取:使用xts包的first函数提取时间序列中最前面10天的数据(first 10 day)
Setting right:0 after sticky positioning does not take effect
经典SQL语句大全
62页智慧冷链产业园整体解决方案2022
开放原子开源基金会为白金、黄金、白银捐赠人授牌,CSDN荣获黄金捐赠人
字节跳动基于 Iceberg 的海量特征存储实践
如何实时计算日累计逐单资金流
开源数据标注工具










