robot framework中get text使用疑问

m0_38131949 2019-04-18 03:23:33

如图的HTML文件 用
${a} get text xpath=/heml/body 来赋值 结果 “Welcome to Login: limin3.”跟“View Defects.”都被get了
如何操作才能只get“Welcome to Login: limin3.”;或者使用其他的关键词及操作?
...全文
492 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
RobotFramework基础教程 基础教程 安装 安装 Pycharm 安装插件 Pycharm File->Settings->Plugins 搜索并安装插件 IntelliBot Run Robot Framework Testcase RunRobot Framework 基本格式 基本格式 Settings Library Resource Force Tags Defalut Tags(未定义任何标签时) Test Setup Test TearDown Test Template Test Timeout Variables Keywords Test Cases [Tags] [Template] [Documention] [Timeout] [Return] [Arguments] [Setup] [TearDown] Suite(⽂件夹) __init__⽂件 library为第三⽅库或⾃定义库,resource为⾃定义关键字集合,variables为⾃定义变量集合 简单⽰例 简单⽰例 Selenium Demo pip install robotframework robotframework-selenium2library *** Setttings *** ** Test Setup ** ... ** Test Teardown ** ... *** Keywords *** loginwebsite [Arguments] ${username} ${password} Open Browser http://... chrome [Return] ${lessons} *** Settings *** Library SeleniumLibrary *** Test Cases *** test rf log hello robot framework Baidu search case Open Browser http://www.baidu.com chrome Input text id=kw robot framework Click button id=su Close Browser baidu_search.robot Headless Demo MySQL操作 操作Demo *** Settings *** Documentation Simple examle using SeleniumLibrary Library SeleniumLibrary *** Variables *** ${URL} http://www.baidu.com ${BROWSER} Chrome *** Keywords *** Baidu Search [Arguments] ${search_key} Input text id:kw ${search_key} click button id:su Evaluate time.sleep(2) time ${title} Get title [Return] ${title} *** Test Case *** case1 Open Browser ${URL} ${BROWSER} ${title} Baidu Search robot framework Should contain ${title} robot framework_百度搜索 close Browser case2 Open Browser ${URL} ${BROWSER} ${title} Baidu Search selenium Should contain ${title} selenium_百度搜索 close Browser *** Settings *** Documentation This example demonstrates how to use current library Library SeleniumLibrary *** Test cases *** Open Browser with Chrome options in headless mode ${options} Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver Call Method ${options} add_argument --start-maximized Call Method ${options} add_argument --headless Call Method ${options} add_argument --disable-gp
robotframework实战三 实战三--⾃定义关键字 ⾃定义关键字 在rf的实战1,我的登录获取验证码就使⽤了⾃定义关键字,具体怎么做的,如下 1.新建⽂件夹 新建⽂件夹 新建⼀个⽂件夹,我的MyLibrary,并且存放在site-packages下 2.编写代码 编写代码 在python的编译器把需要的代码编写完成,并且运⾏成功,以下代码就是获取页⾯的session,⽣成随机数,拿到session+key+随机数,⽣成MD5,在和请求 ⼀起get请求,返回验证码,代码在本地编译没有问题 import random import hashlib import types import requests key="XXXXXXXXX" class verificationCode(object): def __init__(self): self.encryptiontest = '' def code(self,cookie): # 随机数 letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" requestId = [] requestId.append(''.join(random.sample(list(letter), 6))) randomNumber=''.join(requestId) data = "a:1:{s:10:\"session_id\";s:26:\"" + cookie + "\";}" getsign = key + randomNumber + data # 获得密匙 # MD5加密 m = hashlib.md5() m.update(getsign) self.encryptiontest=m.hexdigest() #get请求 url = "https://rosewholesale.com/auto/api.php" textmod = {'XXXX': 'XXX', 'act': 'XXX', 'requestId': randomNumber, 'sign': self.encryptiontest, 'data': data,'ftc': 'XXXX'} r = requests.get(url, params=textmod) print "code:",r.status_code getcontent=r.text print u'返回的内容:',getcontent converturl = str(getcontent) splitStr = converturl[-76:-70] print u'验证码为:',splitStr return splitStr if __name__ == '__main__': verif=verificationCode() verif.code('aq3k8qphile1nrknarpnjb9eg0') 3.⽂件夹创建⼀个 ⽂件夹创建⼀个init⽂件,如下 ⽂件,如下 ⽂件夹包含两个py⽂件 4.rf导⼊⽂件 导⼊⽂件 如果导⼊后没有显⽰红⾊说明导⼊成功 5.使⽤⾃定义关键字 使⽤⾃定义关键字 使⽤F5查找,查看是否引⼊了⽂件夹 使⽤在项⽬ 可以看见我的项⽬是需要⼀个页⾯的cookie,⽬前获取的cookie给了⼀个变量cookie,⽽code就是我们刚刚定义的变量,把cookie给code,在到id为code的 输⼊框进⾏输⼊(验证码输⼊框),输⼊ 你看是否成功,1.界⾯显⽰ 2、⽇志打印,可以看到我们⽇志的每个⾛向
Preface 3 Chapter 6, Routing Magic: Almost every web-based application will eventually have to develop a successful strategy to obtain better search engine position through a technique known as search engine optimization. This chapter starts by introducing some basic concepts of routing through the use of route parameters, and continues to build optimized routes to leverage our search engine placement. The final section in this chapter shows us how to create highly optimized URLs for our user profiles, and how to build custom Route classes to obtain even more flexibility. Chapter 7, Creating and Consuming Web Services: Web services are essential when looking forward to expose application functionality to third-party applications, or when looking forward to integrate foreign services into our own applications. They offer a broad set of technologies and definitions so systems written in different programming languages can communicate. This chapter introduces a set of recipes to consume web services and to expose parts of our application as web services. Chapter 8, Working with Shells: One of the most powerful, yet unknown, features of CakePHP is its shell framework. It provides applications with all that is required for building command line tools, which can be used to perform intensive tasks and any other type of non interactive processing. This chapter introduces the reader to CakePHP shells by starting with the process of building basic shells, and then moving on to more advanced features, such as sending e-mails, and running controller actions from shells. It finishes by presenting the robot plugin, which offers a fully featured solution for scheduling and running tasks. Chapter 9, Internationalizing Applications: This chapter includes a set of recipes that allow the reader to internationalize all aspects of their CakePHP applications, including static content (such as those available in views), and dynamic content (such as database records). The first two recipes show how to allow text that is part of any CakePHP view, or model validation messages, to be ready for translation. The third recipe shows how to translate more complex expressions. The fourth recipe shows how to run CakePHP's built in tools to extract all static content that needs translation, and then translate that content to different languages. The fifth recipe shows how to translate database records. Finally, the last recipe shows how to allow users to change the current application language. Chapter 10, Testing: This chapter covers one of the most interesting areas of application programming: unit testing through CakePHP's built-in tools, which offers a complete and powerful unit testing framework. Download from Wow! eBook Preface 4 The first recipe shows how to set up the test framework so that we can create our own test cases. The second recipe shows how to create test data (fixtures) and use that data to test model methods. The third and fourth recipes show how to test controller actions, and how to test that our views are showing what we expect. The last recipe shows how to run the test in a non-ordinary fashion. Chapter 11, Utility Classes and Tools: This chapter introduces a set of utility classes and helpful techniques that improve the architecture of a CakePHP application. The first recipe shows how to work with a CakePHP class that optimizes the manipulation of arrays. The second recipe shows how to send an e-mail using the Email component. The third recipe shows how to use the MagicDb class to detect the type of a file, and the last recipe shows how to create application exceptions, and properly handle them when they are thrown. What you need for this book We need the following software for the book: f A web server supported by CakePHP (such as Apache) f A database engine supported by CakePHP (such as MySQL) f CakePHP installed, configured, and working properly Who this book is for If you are a CakePHP developer who wants to discover quick and easy ways to improve web applications, and to leverage all aspects of the framework, this book is for you. This book assumes that you already have knowledge of CakePHP and general PHP development skills. Conventions In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning. Code words in text are shown as follows: "Create a file named query_log.php and place it in your app/controllers/components folder with the following contents:" CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying web applications. While the framework has a lot of documentation and reference guides available for beginners, developing more sophisticated and scalable applications require a deeper knowledge of CakePHP features, a challenge that proves difficult even for well established developers. The recipes in this cookbook will give you instant results and will help you to develop web applications, leveraging the CakePHP features that allow you to build robust and complex applications. Following the recipes in this book (which show how to work with AJAX, datasources, GEO location, routing, performance optimization, and more), you will be able to understand and use these features in no time. What this book covers Chapter 1, Authentication: This chapter explains how to set up authentication on a CakePHP application, starting from the most basic setup and finishing with advanced authorization mechanisms. This is accomplished through the use of tools that are built into the framework core, which allow us to quickly set up secure areas, without losing flexibility to build more complex solutions. The first two recipes show us how to set up a basic, yet fully working authentication system. The next three recipes allow our users to log in using different information, have their user details saved after a successful login, and show us how to get this user information. The sixth recipe shows a more complex authorization technique that relies on route prefixes. The seventh recipe sets up a complex authentication system through the use of CakePHP's Access Control Layer. Finally, the last recipe shows us how to integrate our application with OpenID. Chapter 2, Model Bindings: This chapter deals with one of the most important aspects of a CakePHP application: the relationship between models, also known as model bindings or associations. Being an integral part of any application's logic, it is of crucial importance that we master all aspects of how model bindings can be manipulated to get the data we need, when we need it. Preface 2 In order to do so, we will go through a series of recipes that will show us how to change the way bindings are fetched, what bindings and what information from a binding is returned, how to create new bindings, and how to build hierarchical data structures Chapter 3, Pushing the Search: Using models to fetch data is one of the most important aspects of any CakePHP application. As such, a good use of the find functions the framework provides can certainly guarantee the success of our application, and as importantly ensure that our code is readable and maintainable. In this chapter, we have several recipes to resort to manual SQL-based queries when the need arises. CakePHP also lets us define our custom find types that will extend the basic ones, allowing our code to be even more readable. The last recipes in this chapter show us how to add pagination support to our find type. Chapter 4, Validation and Behaviors: This chapter deals with two aspects of CakePHP models that are fundamental to most applications: validation and behaviors. When we are saving information to a data source (such as a database), CakePHP will automatically ensure that the data is quoted in order to prevent attacks, SQL injection being the most common one. If we also need to ensure that the data follows a certain format (for example, that a phone number is valid), we use validation rules. There are also times where we need to do more than just validate the data we are working with. In some cases, we need to set values for fields that the end user can't specify but are part of our application logic. CakePHP's behaviors allow us to extend the functionality provided by a model, using callbacks to manipulate the data before it's saved, or after it's fetched. The third recipe shows us how to use model callbacks (such as beforeFind and afterFind) in behaviors, while the fourth recipe shows how to use behaviors to add additional field values when a save operation is being undertaken. The last two recipes in this chapter give examples on how to use the Sluggable behavior (for creating SEO friendly URLs), and the Geocodable behavior (to add geocoding support to an Address model). Chapter 5, Datasources: Datasources are the backbone of almost all model operations. They provide an abstraction between model logic and the underlying data layer, allowing a more flexible approach to data manipulation. Through this abstraction, CakePHP applications are able to manipulate data without knowing the specifics of how it's stored, or fetched. This chapter shows how to get information from existing datasources, use pre-built datasources to deal with non-relational data, and teaches us how to create a full-featured twitter datasource.

5,177

社区成员

发帖
与我相关
我的任务
社区描述
软件工程/管理 质量管理/软件测试
功能测试压力测试安全性测试 个人社区 湖南省·长沙市
社区管理员
  • 软件测试
  • 虫无涯
  • 小博测试成长之路
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

欢迎大家加入到软件测试的社区,在这里,希望大家勇于发表自己的看法,欢迎大家分享自己在软件测试工作过程中遇到的问题以及工作经验分享。

1.想转行的小伙伴,遇到问题没有及时回复的,可以私聊小博进行反馈

2.大家对社区有好的建议,都可以在社区发帖进行反馈

推荐大家学习的软件测试入门笔记:软件测试入门学习笔记

试试用AI创作助手写篇文章吧