Skip to content

Commit e349f18

Browse files
Abizer Singaporewalafrancisf
authored andcommitted
Code refactor
1 parent c9d6f9e commit e349f18

File tree

9 files changed

+120
-65
lines changed

9 files changed

+120
-65
lines changed

config/Config.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
3+
common_caps = {
4+
"browserstack.user" : "BROWSERSTACK_USERNAME",
5+
"browserstack.key" : "BROWSERSTACK_ACCESS_KEY",
6+
"build" : "browserstack-build-1",
7+
"browserstack.debug" : "true"
8+
}
9+
10+
envs = [{
11+
"os" : "Windows",
12+
"os_version" : "10",
13+
"browser" : "Chrome",
14+
"browser_version" : "latest"
15+
},
16+
{
17+
"os" : "OS X",
18+
"os_version" : "Big Sur",
19+
"browser" : "Safari",
20+
"browser_version" : "latest"
21+
},
22+
{
23+
"device" : "Samsung Galaxy S22",
24+
"os_version" : "12",
25+
"real_mobile" : "true"
26+
}]
27+
28+
def combine_caps(i):
29+
30+
username = os.environ.get("BROWSERSTACK_USERNAME")
31+
accesskey = os.environ.get("BROWSERSTACK_ACCESS_KEY")
32+
if username != None and accesskey != None:
33+
common_caps["browserstack.user"] = username
34+
common_caps["browserstack.key"] = accesskey
35+
36+
x = int(i)
37+
envs[x].update(common_caps)
38+
return envs[x]

config/KeywordsFile.robot

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
*** Settings ***
22
Library SeleniumLibrary
33
Library mark-test-status.py
4-
Library manage-local-testing.py
54

65
*** Variables ***
7-
${USERNAME}= %{BROWSERSTACK_USERNAME}
8-
${ACCESSKEY}= %{BROWSERSTACK_ACCESS_KEY}
9-
${REMOTE_URL}= https://${USERNAME}:${ACCESSKEY}@hub.browserstack.com/wd/hub
6+
${remote_url}= https://hub.browserstack.com/wd/hub
107

118
*** Keywords ***
129
Open Session
13-
[Arguments] ${capabilities} ${website_url}
14-
open browser remote_url=${REMOTE_URL} desired_capabilities=${capabilities} url=${website_url}
10+
[Arguments] ${capabilities} ${test_url}
11+
open browser remote_url=${remote_url} desired_capabilities=${capabilities} url=${test_url}
1512

1613
Close Session
1714
close browser
@@ -23,13 +20,8 @@ Mark Test Status
2320
[Arguments] ${status} ${reason}
2421
TEST STATUS ${status} ${reason}
2522

26-
Setup for local test
27-
START LOCAL
28-
Open Session ${LOCAL_CAPS} ${WEBSITE_URL}
29-
30-
Teardown for local test
31-
Close Session
32-
STOP LOCAL
23+
Get the page title
24+
get title
3325

3426
Click on Sign In
3527
click element id=signin
@@ -56,3 +48,13 @@ Verify site content
5648
run keyword if "${site_content}" == "Up and running" mark test status passed Site Content validated!
5749
run keyword if "${site_content}" != "Up and running" mark test status failed Site Content validation failed!
5850
element should contain css=body Up and running
51+
52+
Add first product to cart
53+
click element xpath=//*[@id="1"]/div[4]
54+
55+
Verify product is added to cart
56+
${product_name} get text xpath=//*[@id="1"]/p
57+
${product_incart} get text css=p.title
58+
run keyword if "${product_name}" == "${product_incart}" mark test status passed Correct product added!
59+
run keyword if "${product_name}" != "${product_incart}" mark test status failed Something went wrong!
60+
element should contain css=p.title ${product_name}

config/LocalCaps.robot

Lines changed: 0 additions & 2 deletions
This file was deleted.

config/ParallelCaps.robot

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/LocalTest.robot

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
*** Settings ***
22
Library SeleniumLibrary
3+
Library Collections
4+
Library ../config/manage-local-testing.py
5+
Library ../config/Config.py
36
Resource ../config/KeywordsFile.robot
4-
Resource ../config/LocalCaps.robot
57
Test Setup Setup for local test
68
Test Teardown Teardown for local test
79

810
*** Variables ***
9-
${WEBSITE_URL}= http://bs-local.com:45691/check
11+
${local_url}= http://bs-local.com:45691/check
12+
13+
*** Keywords ***
14+
Setup for local test
15+
START LOCAL
16+
${final_caps}= combine caps 0
17+
Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME} browserstack.local=true
18+
Open Session ${final_caps} ${local_url}
19+
20+
Teardown for local test
21+
Close Session
22+
STOP LOCAL
1023

1124
*** Test Cases ***
12-
Local Website
25+
Local Test
1326
Add Implicit Wait
1427
Verify site content

tests/parallel/Suite01.robot

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
*** Settings ***
22
Library SeleniumLibrary
3+
Library Collections
4+
Library ../../config/Config.py
35
Resource ../../config/KeywordsFile.robot
4-
Resource ../../config/ParallelCaps.robot
56
Resource ../testcases.robot
6-
Test Setup Open Session ${PARALLEL_CAPS_1} ${WEBSITE_URL}
7+
Test Setup Execute test
78
Test Teardown Close Session
89

910
*** Variables ***
10-
${WEBSITE_URL}= https://bstackdemo.com
11+
${website_url}= https://bstackdemo.com
12+
13+
*** Keywords ***
14+
Execute test
15+
${final_caps}= combine caps 0
16+
Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME}
17+
Open Session ${final_caps} ${website_url}
1118

12-
*** Test Cases ***
13-
Demouser test
14-
Demouser
1519

16-
Favuser test
17-
Favuser
20+
*** Test Cases ***
21+
Login Test
22+
Login
1823

19-
Image not loading user test
20-
Image not loading user
24+
Add to Cart Test
25+
Add to Cart

tests/parallel/Suite02.robot

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
*** Settings ***
22
Library SeleniumLibrary
3+
Library Collections
4+
Library ../../config/Config.py
35
Resource ../../config/KeywordsFile.robot
4-
Resource ../../config/ParallelCaps.robot
56
Resource ../testcases.robot
6-
Test Setup Open Session ${PARALLEL_CAPS_2} ${WEBSITE_URL}
7+
Test Setup Execute test
78
Test Teardown Close Session
89

910
*** Variables ***
10-
${WEBSITE_URL}= https://bstackdemo.com
11+
${website_url}= https://bstackdemo.com
12+
13+
*** Keywords ***
14+
Execute test
15+
${final_caps}= combine caps 1
16+
Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME}
17+
Open Session ${final_caps} ${website_url}
1118

12-
*** Test Cases ***
13-
Demouser test
14-
Demouser
1519

16-
Favuser test
17-
Favuser
20+
*** Test Cases ***
21+
Login Test
22+
Login
1823

19-
Image not loading user test
20-
Image not loading user
24+
Add to Cart Test
25+
Add to Cart

tests/parallel/Suite03.robot

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
*** Settings ***
22
Library SeleniumLibrary
3+
Library Collections
4+
Library ../../config/Config.py
35
Resource ../../config/KeywordsFile.robot
4-
Resource ../../config/ParallelCaps.robot
56
Resource ../testcases.robot
6-
Test Setup Open Session ${PARALLEL_CAPS_3} ${WEBSITE_URL}
7+
Test Setup Execute test
78
Test Teardown Close Session
89

910
*** Variables ***
10-
${WEBSITE_URL}= https://bstackdemo.com
11+
${website_url}= https://bstackdemo.com
12+
13+
*** Keywords ***
14+
Execute test
15+
${final_caps}= combine caps 2
16+
Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME}
17+
Open Session ${final_caps} ${website_url}
1118

12-
*** Test Cases ***
13-
Demouser test
14-
Demouser
1519

16-
Favuser test
17-
Favuser
20+
*** Test Cases ***
21+
Login Test
22+
Login
1823

19-
Image not loading user test
20-
Image not loading user
24+
Add to Cart Test
25+
Add to Cart

tests/testcases.robot

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,16 @@ Library SeleniumLibrary
33
Resource ../config/KeywordsFile.robot
44

55
*** Keywords ***
6-
Demouser
6+
Login
77
Add Implicit Wait
8+
Get the page title
89
Click on Sign In
910
Enter Credentials demouser testingisfun99
1011
Click on Login
1112
Verify username demouser
1213

13-
Favuser
14+
Add to Cart
1415
Add Implicit Wait
15-
Click on Sign In
16-
Enter Credentials fav_user testingisfun99
17-
Click on Login
18-
Verify username fav_user
19-
20-
Image not loading user
21-
Add Implicit Wait
22-
Click on Sign In
23-
Enter Credentials image_not_loading_user testingisfun99
24-
Click on Login
25-
Verify username image_not_loading_user
16+
Get the page title
17+
Add first product to cart
18+
Verify product is added to cart

0 commit comments

Comments
 (0)