Tuesday, October 7, 2014

Python Basics: 2

Lists and Tuples

Indexing
a = "python"
a[0]
p

Slicing
a = "python"
a[1:] = list("erl")
perl

Memebership
a = ["Perl","Python"]
"Perl"  in a
True
"Ruby" in a
False

List is a Function and it is mutable (i.e You can change their contents)

1. Changing elements
2. Deleting elements

Methods in Lists:
1. append
2. count
3. extend
4. index
5. insert
6. pop
7.remove
8. reverse
9.sort



Tuples are sequences like Lists, But it cant be changed

Python Dictionaries

Python Dictionaries:

Functions:

 dict is a function, which is used to construct dictionaries from other mappings.

Methods:

1. clear
2. copy
3. fromkeys
4. get
5. has_key
6. items and iteritems
7. pop
8. popitem
9. setdefault
10.update
11. values and itervalues

Python Basics:

Assigning variable & Concatenating:

x = "Hello"
y = "World!"

x + y
'Hello World!'

String representations

a = "Hello1"

repr(a)
"'Hello1'"

str(a)
'Hello1'

x = 123

str(x)
'123'

rep(a)
'123'


*** Settings ***
Documentation   Testing Website for learning selenium
Library  Selenium2Library
Library  OperatingSystem
Test Setup  open browser  http://adam.goucher.ca/parkcalc/    chrome
Test Teardown  close browser

*** Test Cases ***
Check the parking charges
    Choose start time
    Choose start date
    Choose end time
    Choose end date
    Submit and check the cost

*** Keywords ***
Choose start time
    maximize browser window
    select from list by value  id=Lot    LTG
    input text  id=EntryTime    20:00
    select radio button  EntryTimeAMPM    PM
    click element  xpath=//form/table/tbody/tr[2]/td[2]/font/a/img
    select window    title=Pick a Date

Choose start date
    click element  xpath=//form/table/tbody/tr[1]/td/table/tbody/tr/td[1]/select
    wait until page contains  Su
    select from list by label  name=MonthSelector    October
    click element  xpath=//form/table/tbody/tr[4]/td[7]/font/a

Choose end time
    select window  title=Parking Calculator
    input text  id=ExitTime    22:00
    select radio button  ExitTimeAMPM    PM

Choose end date
    click element  xpath=//form/table/tbody/tr[3]/td[2]/font/a/img
    select window    title=Pick a Date
    click element  xpath=//form/table/tbody/tr[1]/td/table/tbody/tr/td[1]/select
    wait until page contains  Su
    select from list by label  name=MonthSelector    October
    click element  xpath=//form/table/tbody/tr[5]/td[2]/font/a

Submit and check the cost
    select window  title=Parking Calculator
    click element  name=Submit
    ${ATR}=    get text    xpath=//form/table/tbody/tr[4]/td[2]/span[1]/font/b
    should be equal    ${ATR}    $ 28.00