1
1
from selenium .webdriver .common .by import By
2
+ from selenium .webdriver .support import expected_conditions
3
+ from selenium .webdriver .support .ui import WebDriverWait
2
4
import pytest
3
-
4
- from codebender_testing .config import TESTS_USER_AGENT
5
- from codebender_testing .config import TESTS_USER_AGENT_CHROME
6
- from codebender_testing .config import BROWSER
5
+ import os
6
+ from codebender_testing .config import SELENIUM_BROWSER
7
+ from codebender_testing .config import TIMEOUT
7
8
from codebender_testing .utils import SeleniumTestCase
8
9
from codebender_testing .utils import SELECT_BOARD_SCRIPT
9
10
10
11
TEST_BOARD = 'Arduino Uno'
11
12
12
13
13
- class TestUserHome (SeleniumTestCase ):
14
+ class TestWalkthrough (SeleniumTestCase ):
14
15
15
16
@pytest .fixture (scope = "class" , autouse = True )
16
17
def open_user_home (self , tester_login ):
@@ -29,20 +30,11 @@ def test_page_2(self):
29
30
30
31
def test_page_3 (self ):
31
32
"""Test page 3"""
32
- if BROWSER == "firefox" :
33
- if 'Linux' in TESTS_USER_AGENT :
34
- self .get_element (By .CSS_SELECTOR , '#linux-directions .btn:nth-child(2)' ).click ()
35
- elif 'Windows' in TESTS_USER_AGENT :
36
- self .get_element (By .CSS_SELECTOR , '#windows-directions .btn:nth-child(2)' ).click ()
37
- elif 'Mac' in TESTS_USER_AGENT :
38
- self .get_element (By .CSS_SELECTOR , '#mac-directions .btn:nth-child(2)' ).click ()
39
- elif BROWSER == "chrome" :
40
- if 'Linux' in TESTS_USER_AGENT_CHROME :
41
- self .get_element (By .CSS_SELECTOR , '#linux-directions .btn:nth-child(2)' ).click ()
42
- elif 'Windows' in TESTS_USER_AGENT_CHROME :
43
- self .get_element (By .CSS_SELECTOR , '#windows-directions .btn:nth-child(2)' ).click ()
44
- elif 'Mac' in TESTS_USER_AGENT_CHROME :
45
- self .get_element (By .CSS_SELECTOR , '#mac-directions .btn:nth-child(2)' ).click ()
33
+ user_agent = self .execute_script ('return navigator.userAgent' )
34
+ platforms = ['Linux' , 'Windows' , 'Mac' ]
35
+ for platform in platforms :
36
+ if platform in user_agent :
37
+ self .get_element (By .CSS_SELECTOR , '#{0}-directions .btn:nth-child(2)' .format (platform .lower ())).click ()
46
38
47
39
def test_page_4 (self ):
48
40
"""Test page 4"""
@@ -54,8 +46,15 @@ def test_page_4(self):
54
46
cb_cf_flash_btn = self .get_element (By .CSS_SELECTOR , '#cb_cf_flash_btn' )
55
47
assert cb_cf_flash_btn .is_displayed ()
56
48
cb_cf_flash_btn .click ()
49
+ WebDriverWait (self .driver , TIMEOUT ['FLASH_FAIL' ]).until (
50
+ expected_conditions .element_to_be_clickable ((By .CSS_SELECTOR , '#cb_cf_flash_btn' ))
51
+ )
57
52
cb_cf_operation_output = self .get_element (By .CSS_SELECTOR , '#cb_cf_operation_output' )
58
- assert cb_cf_operation_output .text .strip () == 'Please select a valid port!'
53
+ assert cb_cf_operation_output .text .strip () in [
54
+ 'Please select a valid port!' ,
55
+ 'The specified port might not be available. Please check if it is used by another application. If the problem persists, unplug your device and plug it again. More Info' ,
56
+ 'An error occurred while connecting to your device. Please try again.'
57
+ ]
59
58
board_image = self .get_element (By .CSS_SELECTOR , '#arduinoImg' )
60
59
assert board_image .is_displayed ()
61
60
0 commit comments