Create Script Test In TestComplete Using Python For Web Application

Back to Blog
TestComplete

Create Script Test In TestComplete Using Python For Web Application

Two Ways to Create a Script

In TestComplete there are two ways to create a script & these are following

  1. Record a script test
  2. Write a script test manually in the Code Editor in TestComplete

Let’s Begin, First, we need to create a new project by following the below steps:-

  1. Click the File -> New->New Project option from the menu bar.
  2. New Project Window will appear, giving a name to the project, setting the project location, and selecting the scripting language “Python”.
  3. Click on Finish.

When you create a new project, TestComplete automatically creates the Script project item with one unit in it. You can rename it accordingly and add more.
You can see it under <YourProject>->Script named Unit1.

Steps to Record a Test Script

Follow the below steps to record a test script:

  1. Select Test > Record > Record Script from the TestComplete main menu.
  2. After step 1, TestComplete minimizes, so you can perform actions that you need to record.

Here we need a script test to cover the flow to opening Gmail, logging in, and logging out, so open the browser, open the Gmail app, and login into your account, and do logout.

  1. After performing all actions that you need to record, Stop the recording by Click Stop on the Recording toolbar.TestComplete will be maximized where you can see the recorded script in Unit 1.

Your first script record was successful, now you can modify it accordingly.

Read Also:- Read PDF File Using Python in Robot Framework

Let’s take a look at the modified recorded script code:

def Test1():

 #Open Gmail on the browser chrome

  Browsers.Item[bt.Chrome].Run("https://www.gmail.com");

  browser = Sys.Browser()

  page = browser.Page("https://accounts.google.com/*")

  #Gmail Login

  emailInput = page.FindElement(Project.Variables.email_xpath)

  emailInput.SetText(“[email protected]”)

  nextBtn = page.QuerySelector(Project.Variables.nextemail_css)

  nextBtn.Click()

  Delay(1000,"wait for password input field visible")

  passwordInput = page.FindElement(Project.Variables.password_xpath) 

  passwordInput.SetText(“123456”)

  nextBtn = page.QuerySelector(Project.Variables.nextpass_css)

  nextBtn.Click()

  Delay(1000,"wait for user login")

  page = browser.Page("https://mail.google.com/mail/u/0/#inbox")
  #Gmail Logout
  signoutoption = page.FindElement(Project.Variables.signoutoption_xpath)

  signoutoption.Click()

  signout = page.FindElement(Project.Variables.signout_xpath)

  signout.Click()

Read Also:- Read Excel Using Python in Robot Framework

Note: In the above code

  1. Project. Variables are used to fetch defined project variables.
  2. FindElement is used for the Xpath type of locator
  3. QuerySelector is used for CSS type of locator
FAQs
  • How do I import a Python library into TestComplete?

Importing a unique Python package

The package file (.py) should be placed in the following folder: If you’re using TestComplete’s 64-bit version, enter this command instead: TestComplete>x64BinExtensionsPythonPython38Lib. If you utilize TestComplete in 32-bit mode:

Use the import command in your script test to import: Copy the code. import the package in.

  • Apache Jmeter vs Testcomplete

The performance of two automation testing tools, Apache JMeter and TestComplete, has been assessed regarding factors, such as load performance, response time, etc. concerning the number of users or threads, to test web services and web pages.

  • Examples of test automation framework

A test automation example

Selenium is an open-source framework for testing online applications across platforms and web browsers. It is a set of tools that enables automated testing of websites and online apps across many platforms, browsers, and programming languages.

  • What is the role of Python in network automation?

Python can communicate with network controllers like Cisco DNA Center or OpenDaylight in addition to automating devices one at a time. Utilize the REST API to get network inventory database data. Find a host by its MAC or IP address.

——————————————————————————————————————————————-

If you are interested in even more software testing-related articles and information from us here at Devstringx, then we have a lot to choose from for you.

Share this post

Back to Blog