Create Script Test In TestComplete Using Python For Web Application

Back to Blog

Create Script Test In TestComplete Using Python For Web Application

In TestComplete there are two ways to create a script:

  • Record a script test.

  • Write a script test manually in the Code Editor in TestComplete.

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

  1. Click  File -> New->New Project option from menu bar.
  2. New Project Window will appear, giving a name to the project,set project location,select 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 .

Follow 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 flow to open gmail,login and logout, so open browser,open 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 maximised where you can see the recorded script in Unit1.

Your first script recorded successfully, now you can modify it accordingly.

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

def Test1():

 #Open Gmail on browser chrome


  browser = Sys.Browser()

  page = browser.Page(“*”) 

  #Gmail Login

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

  emailInput.SetText(“[email protected]”)

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


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

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


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


  Delay(1000,”wait for user login”)

  page = browser.Page(“”) 

  #Gmail Logout

  signoutoption = page.FindElement(Project.Variables.signoutoption_xpath)


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


Note: In Above code, 

  1. Project.Variables is used to fetch defined project variables.
  2. FindElement is used for Xpath type of locator
  3. QuerySelector is used for CSS type of locator


Share this post

Back to Blog