More advanced test example: test twitter!

Tutorial description

In this tutorial we will create more advanced test-case for Twitter. We’ll test two twitter use-cases: changing background and sending tweets. Let’s start from changing background test and define steps:

Test changing background

  • Go to
  • Login, enter username and password
  • Go to settings page and change background
  • Return background to previous state
  • Logout

Test sending tweets

Second test will do following steps:

  • Go to
  • Login, enter username and password
  • Post two tweets
  • Select favorite tweet and check it
  • Delete created tweets
  • Logout

As you see, both tests have common steps: go to, login, logout, and other. In this tutorial we’ll use <before>, <after> and <frame> features to avoid copy-pasting. Also we’ll periodically save screenshots and snapshots (html content of the page) and record test video.

1. Navigate and login to

From previous tutorial you know how to create test-case, test and navigate to web-page. In this example we leave this behind the scenes. We start from login to twitter using <field id=”signin-email” textToType=””/> and <field id=”signin-password” textToType=”9xANjIXML8″/> and then click to ‘Submit’ button <button xpath=”//div[@id=’front-container’]//td[@class=’flex-table-secondary’]/button[@type=’submit’]”/>. Here we put this commands to <before> section. This commands will be executed before our test runs.








2. Adding logout step

Before we run our test we add logout step. This allows us to concentrate on business logic in our test, but not on authorization details. For logout logic we use <after> feature. Logout code will be executed after test finish.









3. Change twitter background

Now it’s time for change twitter background. This operation will be used two times: for change and for return back. XML2Selenium has powerful feature called frames. We can put common code to frame and then re-use this code in our tests. To put theme id into frame we use <variable>. Our frame will look this way:





This code changes background by clicking several buttons. To make frame reusable we will pot it into separate text file, called “ImportFile for twitter.xml”. File contents is listed below:





Then we’ll include this import to our test and call this code, also add videorecording:










4. Sending tweets

For sending tweets we implement another test. This helps us to split different logical tests. For this test we implement three new frames and put them into “ImportFile for twitter.xml”:



5. Putting it’s all together

As a result we have following import file with frames:







And following test-case with two tests:



















After executing this test we’ll get following aftifacts:

Leave a Comment