Print information-whether the script was run successfully

Source: Internet
Author: User

When we want to design functional test cases, we generally have the expected results, and some of the expected results are judged by the human eye by the tester. Because the automated test run process is unattended, in general, the script runs successfully, and there is no unusual information to identify the user execution success. Of course, this is not going to be enough to clear that a use case is really successful in execution. So we need to get more information to prove that the use case execution results are really successful.
Usually we can determine the success of a use case by getting the title of the page, the URL address, the identifying information on the page (for example, the "Welcome, XXX" message, which is a successful login).


In the actual test, access to 1 pages to determine whether its title is expected to be a very common use case, if a page title should be "Fast broadcast private Cloud", then the use case can be described as: access to the page, to determine whether the page title is equal to "fast broadcast private cloud." Getting the current URL is also a very important operation, in some cases, you access a URL, then the system will automatically jump to this URL, which is called "redirection." The generic test redirection method is to access the URL, and then wait for the page to be redirected, get the URL of the current page, and determine if the URL is expected. If the ULR of the page is returned incorrectly, the current operation does not have a normal jump.


The following is explained by a fast-seeding private cloud Login instance:

code example:

#coding =utf-8
From selenium import Webdriver

Driver = Webdriver. Firefox ()
Driver.get ("Http://passport.kuaibo.com/login/?referrer=http%3A%2F%2Fwebcloud.kuaibo.com%2F")

#登录
DRIVER.FIND_ELEMENT_BY_ID ("user_name"). Clear ()
DRIVER.FIND_ELEMENT_BY_ID ("user_name"). Send_keys ("username")
driver.find_element_by_id ("User_pwd"). Clear ()
driver.find_element_by_id ("User_pwd"). Send_keys ("password")
driver.find_element_by_id ("Dl_an_submit"). Click ()

#获得当前页面title并打印
title = Driver.title
Print title

#拿当前title Compare with expected title
if title = = U "Fast-seeding private cloud":
Print "Title ok!"
Else
Print "Title on!"

#获得当前URL并打印
Now_url = Driver.current_url
Print Now_url

#拿当前URL Compare to expected URLs
if Now_url = = "http://webcloud.kuaibo.com/":
Print "URL ok!"
Else
Print "URL on!"

#获得登录成功的用户并打印
Now_user=driver.find_element_by_xpath ("//div[@id = ' Nav ']/ul/li[4]/a[1]/span"). Text

Print Now_user

Driver.quit ()

Description

In this case, the new method is covered as follows:


Title: Returns the caption of the current page
Current_url: Gets the URL of the currently loaded page


In the example above we used Python's if judgment statement, which is not different from other languages, and the Python if statement block uses a colon (:) to represent the statements that need to be executed later.

Print information-whether the script was run successfully

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.