challenges in test automation for web apps

Post on 11-Aug-2015

140 Views

Category:

Software

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Challenges in Test Automation for Web Apps

Sudara Madushan Fernando,

Graduate Trainee, hSenid Business Solutions.

Scripting Time

Keeping in touch with the Browser

Changes in the System

Dynamic elementsCoding without QA

Copy (Ctrl + C) and Paste (Ctrl + V)

Maintaining the maintainability100% success rate

Scripting Time• Scripting Time = Time you take to code a test case NOT the time it takes to run

the test case

• Why we need to spend less time in scripting and lots of time in running them? Because it is what QA does!

• The biggest disadvantage Automation has against Manual Testing is the time “wasted” on scripting

Results

Scripting time

PR

OB

LEM

Scripting TimeS

OLU

TIO

N

• In most of the test cases the steps of doing something is repeating Test case 01 – Test if a user can apply a leave on a holiday Test case 02 – Test if a user can apply a leave on a working day

• Understanding this, Selenium Developers introduced The Page Object Model

• Up to

60% less time in scripting!

Copy and Paste• Windows’ highly used feature is NOT going to help us in test scripting!

• It WILL make the test cases less maintainable. PR

OB

LEMStep

01• Log in

Step 02

• Apply leave

Step 03

• Capture error message

Step 01

• Log in

Step 02

• Apply leave

Step 03

• Capture success

• message

Copy (Ctrl + C) and Paste (Ctrl + V)PR

OB

LEM

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

• What will happen if an ID is changed?

• What will happen if steps of doing “it” is changed?

SO

LUTIO

N

• Introduce a third party – Intermediary class for managing “actions”

Copy (Ctrl + C) and Paste (Ctrl + V)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Keeping in touch with the Browser• In Web App automation – TWO things are happening parallel

Getting web page elements and rendering them by the Browser Initializing and running test scripts by the Selenium Web Driver

• If one is faster than the other OR if one is slower than the other, test case IS FAILING!

• Selenium will NEVER wait for the browser UNLESS we ask it to.

• Browser has no idea that the Selenium in running behind – so it won’t wait either

• We have to bridge the GAP!

PR

OB

LEM

Keeping in touch with the BrowserPR

OB

LEM

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

Keeping in touch with the BrowserPR

OB

LEM

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

Keeping in touch with the BrowserS

UG

GES

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Thread.Sleep(5000);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

Using Thread.Sleep()

Keeping in touch with the BrowserS

UG

GES

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Thread.Sleep(5000);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

What if we are waiting 5 seconds and element takes 8 seconds to load?

Keeping in touch with the BrowserS

UG

GES

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Thread.Sleep(10000);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

If it is the case then we can wait for 10 seconds!

Keeping in touch with the BrowserS

UG

GES

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Thread.Sleep(10000);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

What if it loads in 2 seconds?

SO

LUTIO

N

• We should ask the Thread to WAIT rather than SLEEPING!

• If the Thread can wait for the number of seconds that the element takes to load, that is our SOLUTION

• But we will NEVER be able to predict how long it takes to load an element, might be 2 seconds, 5 seconds or even 12 seconds!

• Selenium has the answer - WebDriverWait

Keeping in touch with the Browser

SO

LUTIO

NKeeping in touch with the Browser

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));

wait.Until(b => driver.FindElement(By.Id(“username”).Displayed);

Keeping in touch with the BrowserS

OLU

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

wait.Until(b =>

(“username”).Displayed);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

Now it will start executing, as soon as the element is loaded

Dynamic Elements• Auto generating elements are called Dynamically generated elements, no body

can predict that dynamic elements actually exist in a page until the page is rendered.

• Catching a dynamic element is the worst nightmare of an automation scriptor.

• To make things worse, sometimes we may not be able to identify an element as a dynamic element.

• If you are catching a dynamic element, your test case MAY FAIL or PASS, depending on the status of that element.

PR

OB

LEM

Dynamic ElementsPR

OB

LEM

Dynamic ElementsPR

OB

LEM

SO

LUTIO

N

• Since the ID of a dynamic element can change, try to use other stable locators – such as the Tag name

• We might have to depend on the code structure of the web page or the DOM (Document Object Model)

Dynamic Elements

IList<IWebElement> rows = driver.FindElement(By.Id(“table”))

.FindElements(By.Tagname(“tr”));foreach(IWebElement row in rows){

Cells = element.FindElements(By.Tagname(“td”));}

Maintaining the Maintainability• Is “once written – it’s over” working for automation scripts?

• When the system is updated, do we have to start from the beginning? If we have to, then we are spending a lot of time on scripting!

• We will have to maintain the scripts doing changes as and when it happens on the system.

PR

OB

LEM

SO

LUTIO

N

• The System is changing all the time. But are the test cases?

• “Check if a user can apply a leave” – won’t change as long as our system is allowing a user to apply a leave

• DEFINITION of a test case is the same – IMPLEMENTATION is different

• So DEFINE in one class, and IMPLEMENT in another class, it is what Page Object Model encourages us

• Have a class for each Page, code the activities that page can do in that class

Maintaining the Maintainability

SO

LUTIO

NMaintaining the Maintainability

SO

LUTIO

NMaintaining the Maintainability

Coding without QAPR

OB

LEM

• Nobody can code 100% bug free software – but automation scripters have to!

• Automation Scripts are not sent for QA – if it is, it will be an additional burden on the team

• Coding 100% bug free software is a challenge it self, but doing that without QA?

SO

LUTIO

N

• You will laugh at me when I say that the solution is to send the scripts for QA – So I won’t!

• If you complete a test case, run it once and say “I am done” – I will laugh at you!

• The more number of times you run your test case, the more perfect it is going to be.

• Run and run and run, you will find bugs yourself, this eliminates the need for QA**.

Coding without QA

**only applies to Automation scripts – if you think you can do the same with the System, we all will laugh at you!

Questions?PR

OB

LEM

Thank you!

top related