Skip to content

Releases: seleniumbase/SeleniumBase

Add option: "--enable-ws" to enable Chrome's Web Security

30 Aug 01:48
04e71ca
Compare
Choose a tag to compare

Add option: --enable-ws to enable Chrome's Web Security

SeleniumBase disables Chrome's Web Security by default. Read https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome to learn why. In some special cases, there may be reasons to keep it enabled for automated testing. Now there's a way to keep it enabled, by using --enable-ws.

Additional changes:

  • Scroll to iframes before switching into them
  • Update the Brython integration example
  • Update Python dependencies:
    -- more-itertools==8.5.0;python_version>="3.5"
    -- prompt-toolkit==3.0.7;python_version>="3.6.1"
    -- ipython==7.18.1;python_version>="3.7"
    -- brython==3.8.10

Fix issue with clicking partial_link_text in demo/slow mode

28 Aug 19:04
Compare
Choose a tag to compare

Fix issue with clicking partial_link_text in demo/slow mode

Update the default version of EdgeDriver installed

28 Aug 05:46
e3cb810
Compare
Choose a tag to compare

Update the default version of EdgeDriver installed

  • DEFAULT_EDGEDRIVER_VERSION = 85.0.564.41
  • Also keep Python dependencies up-to-date
  • Update example tests

Update mobile-mode messages, an error message, and reqs

26 Aug 22:14
8129df8
Compare
Choose a tag to compare

Update mobile-mode messages, an error message, and reqs

  • Update message location for mobile mode
  • Update an error message for trying to pass a non-string as a selector
  • Update "pytest-rerunfailures" dependency

Update methods and console scripts

26 Aug 04:49
9f405bd
Compare
Choose a tag to compare

Update methods and console scripts

  • Add the has_exception() method for use in a tearDown() step.
    """
    (This method should ONLY be used in custom tearDown() methods.)
    This method returns True if the test failed or raised an exception.
    This is useful for performing additional steps in your tearDown()
    method (based on whether or not the test passed or failed).
    Example use cases:
        * Performing cleanup steps if a test didn't complete.
        * Sending test data and/or results to a dashboard service.
    """
  • Update the boilerplate example by adding has_exception() usage.
def tearDown(self):
        self.save_teardown_screenshot()
        if self.has_exception():
            # <<< Run custom code if the test failed. >>>
            pass
        else:
            # <<< Run custom code if the test passed. >>>
            pass
        # (Wrap unreliable tearDown() code in a try/except block.)
        # <<< Run custom tearDown() code BEFORE the super().tearDown() >>>
        super(BaseTestCase, self).tearDown()
  • Update the sbase mkdir DIR_NAME console script.
  • Fix the xpath-to-css-selector converter.
  • Update Python dependencies (pytest-xdist and rich).

Fix iframes in presentations and update smart-word-wrap

25 Aug 07:37
fcaba6c
Compare
Choose a tag to compare

Fix iframes in presentations and update smart-word-wrap

  • Fix html when creating an iframe in a Presenter presentation
  • Update smart-word-wrap in sbase print and sbase translate

Make improvements to smart-word-wrap

23 Aug 07:12
b02e820
Compare
Choose a tag to compare

Make improvements to smart-word-wrap

  • SeleniumBase smart-word-wrap is used when displaying code to the console when using the sbase print or sbase translate commands. In the case that the console is not wide enough to display an entire line of code, the code will be wrapped in such a way that Python syntax rules are not broken. This is different from a standard word wrap where code will begin at the very start of the next line, rather than following Python indentation rules.

  • Here's an example of smart-word-wrap on a narrow console screen:

$ sbase print basic_test.py -n
-------------------------------------------
   1 from seleniumbase import BaseCase     
   2                                       
   3                                       
   4 class MyTestClass(BaseCase):          
   5                                       
   6     def test_basic(self):             
   7         self.open(                    
   8             "https://"                
   9             "store.xkcd.com/search")  
  10         self.type(                    
  11             'input[name="q"]',        
  12             "xkcd book\n")            
  13         self.assert_text(             
  14             "xkcd book",              
  15             "div.results")            
  16         self.open(                    
  17             "https://xkcd.com/353/")  
  18         self.click('a[rel="license"]')
  19         self.go_back()                
  20         self.click_link_text("About") 
  21         self.click_link_text(         
  22             "comic #249")             
  23         self.assert_element(          
  24             'img[alt*="Chess"]')      
-------------------------------------------
  • Here's how that same test looks when printing to a wide console screen:
$ sbase print basic_test.py -n
-----------------------------------------------------------
   1 from seleniumbase import BaseCase                     
   2                                                       
   3                                                       
   4 class MyTestClass(BaseCase):                          
   5                                                       
   6     def test_basic(self):                             
   7         self.open("https://store.xkcd.com/search")    
   8         self.type('input[name="q"]', "xkcd book\n")   
   9         self.assert_text("xkcd book", "div.results")  
  10         self.open("https://xkcd.com/353/")            
  11         self.click('a[rel="license"]')                
  12         self.go_back()                                
  13         self.click_link_text("About")                 
  14         self.click_link_text("comic #249")            
  15         self.assert_element('img[alt*="Chess"]')      
-----------------------------------------------------------
  • SeleniumBase smart-word-wrap also works with sbase translate:
$ sbase translate basic_test.py --ja -p -n

 basic_test.py was translated to Japanese! (Previous: English)

  ***  Here are the results:  >>> 
-------------------------------------------------
   1 from seleniumbase.translate.japanese \      
   2     import セレニウムテストケース           
   3                                             
   4                                             
   5 class MyTestClass(セレニウムテストケース):  
   6                                             
   7     def test_basic(self):                   
   8         self.を開く(                        
   9             "https://store.xkcd.com/search")
  10         self.入力(                          
  11             'input[name="q"]',              
  12             "xkcd book\n")                  
  13         self.テキストを確認する(            
  14             "xkcd book", "div.results")     
  15         self.を開く("https://xkcd.com/353/")
  16         self.クリックして(                  
  17             'a[rel="license"]')             
  18         self.戻る()                         
  19         self.リンクテキストをクリックします(
  20             "About")                        
  21         self.リンクテキストをクリックします(
  22             "comic #249")                   
  23         self.要素を確認する(                
  24             'img[alt*="Chess"]')            
-------------------------------------------------
  • Here's how that same translation looks on a wide screen:
$ sbase translate basic_test.py --ja -p -n

 basic_test.py was translated to Japanese! (Previous: English)

  ***  Here are the results:  >>> 
-------------------------------------------------------------------------
   1 from seleniumbase.translate.japanese import セレニウムテストケース  
   2                                                                     
   3                                                                     
   4 class MyTestClass(セレニウムテストケース):                          
   5                                                                     
   6     def test_basic(self):                                           
   7         self.を開く("https://store.xkcd.com/search")                
   8         self.入力('input[name="q"]', "xkcd book\n")                 
   9         self.テキストを確認する("xkcd book", "div.results")         
  10         self.を開く("https://xkcd.com/353/")                        
  11         self.クリックして('a[rel="license"]')                       
  12         self.戻る()                                                 
  13         self.リンクテキストをクリックします("About")                
  14         self.リンクテキストをクリックします("comic #249")           
  15         self.要素を確認する('img[alt*="Chess"]')                    
-------------------------------------------------------------------------

(Smart-word-wrap only effects console printing. It has no effect on the test itself.)

Add a method for getting the browser's Locale Code

22 Aug 22:44
36249a2
Compare
Choose a tag to compare

Add a method for getting the browser's Locale Code

  • Add method: self.get_locale_code()
  • Add language translations for self.get_locale_code()
  • Add examples for testing the browser's Locale Code

To set the browser's Locale Code for tests, add the following to your pytest run command:

--locale=LOCALE_CODE

Example: (from the examples/ folder)

$ pytest locale_code_test.py --locale=he-IL

To determine your browser's default Locale Code, here's a test that you can run: (from the examples/ folder)

$ pytest test_get_locale_code.py
============================= test session starts ===============================
platform darwin -- Python 3.7.0, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /Users/michael/github/SeleniumBase, configfile: pytest.ini
plugins: xdist-2.0.0, html-2.0.1, rerunfailures-9.0, metadata-1.10.0,
allure-pytest-2.8.18, ordering-0.6, cov-2.10.1, forked-1.3.0, seleniumbase-1.47.3
collected 1 item                                                              

test_get_locale_code.py 
Locale Code = "en-US"
.

============================== 1 passed in 7.45s ================================

Here's a reminder that pytest can be run in Quiet Mode with -q to reduce debug statements:

$ pytest test_get_locale_code.py -q

Locale Code = "en-US"
.
1 passed in 7.18s

Update message output from the SeleniumBase translator

22 Aug 05:33
b3e47b3
Compare
Choose a tag to compare

Update message output from the SeleniumBase translator

  • This only effects messages, and not the actual translations.
  • The error output is significantly improved.

Here are some examples of using the sbase translate ability on the command-line:

$ sbase translate basic_test.py --ko -p

 basic_test.py was translated to Korean! (Previous: English)

  ***  Here are the results:  >>> 
----------------------------------------------------------------
from seleniumbase.translate.korean import 셀레늄_테스트_케이스  
                                                                
                                                                
class MyTestClass(셀레늄_테스트_케이스):                        
                                                                
    def test_basic(self):                                       
        self.열기("https://store.xkcd.com/search")              
        self.입력('input[name="q"]', "xkcd book\n")             
        self.텍스트_확인("xkcd book", "div.results")            
        self.열기("https://xkcd.com/353/")                      
        self.클릭('a[rel="license"]')                           
        self.뒤로()                                             
        self.링크_텍스트를_클릭합니다("About")                  
        self.링크_텍스트를_클릭합니다("comic #249")             
        self.요소_확인('img[alt*="Chess"]')                     
----------------------------------------------------------------

Here's an example of attempting to translate a file that was already in the new language specified:

$ sbase translate basic_test.py --en -p

 basic_test.py was already in English!

  ***  No changes to display!  *** 

Here's an example of trying to translate a file that is missing the from seleniumbase import of a BaseCase in one of the ten currently-supported languages:

$ sbase translate boilerplates/boilerplate_test.py --fr -p

 * In order to translate the script,
 boilerplates/boilerplate_test.py requires "from seleniumbase..."
 and a BaseCase import in a supported language!

  ***  No changes to display!  *** 

Here's one more working example of a SeleniumBase translation:

$ sbase translate test_tinymce.py --ru -p

 test_tinymce.py was translated to Russian! (Previous: English)

  ***  Here are the results:  >>> 
-----------------------------------------------------------------------------------
import re                                                                          
from seleniumbase.translate.russian import ТестНаСелен                             
                                                                                   
                                                                                   
class MyTestClass(ТестНаСелен):                                                    
                                                                                   
    def click_menu_item(self, text):                                               
        self.спать(0.2)                                                            
        soup = self.get_beautiful_soup(self.получить_источник_страницы())          
        pattern = re.compile('%s' % text)                                          
        the_id = soup.find(text=pattern).parent.parent.attrs["id"]                 
        self.нажмите("#%s" % the_id)                                               
                                                                                   
    def test_base(self):                                                           
        self.открыть("https://seleniumbase.io/other/tinymce")                      
        self.ждать_элемента("div.mce-container-body")                              
        self.click_menu_item("File")                                               
        self.click_menu_item("New document")                                       
        self.click_menu_item("Paragraph")                                          
        self.click_menu_item("Heading 2")                                          
        self.переключиться_на_кадр("iframe#mce_1_ifr")                             
        self.добавить_текст("#tinymce", "Automate anything with SeleniumBase!\n")  
        self.переключиться_на_содержимое_по_умолчанию()                            
        self.нажмите('button i.mce-i-image')                                       
        self.введите('input[aria-label="Width"].mce-textbox', "300")               
        image_url = "https://seleniumbase.io/img/sb_logo_10.png"                   
        self.введите("input.mce-textbox", image_url + "\n")                        
        self.переключиться_на_кадр("iframe#mce_1_ifr")                             
        self.нажмите("h2")                                                         
        self.переключиться_на_содержимое_по_умолчанию()                            
        self.показать_сообщение("Automate anything with SeleniumBase!")            
        self.click_menu_item("File")                                               
        self.click_menu_item("Preview")                                            
        self.переключиться_на_кадр('iframe[sandbox="allow-scripts"]')              
        self.показать_сообщение("Learn SeleniumBase Today!")                       
-----------------------------------------------------------------------------------

Improve the "seleniumbase install DRIVER" command

21 Aug 03:51
d05d1a7
Compare
Choose a tag to compare

Improve the seleniumbase install DRIVER command

  • Detect the newest version of drivers based on specific browser versions
  • Determine if a newer driver version is available during install
  • Color-coded feedback to highlight download-related actions

Also:

  • Detect if using an out-of-date ChromeDriver during hover actions
  • Add a test to detect if using an out-of-date ChromeDriver or Chrome

And:

  • Update Python dependencies
    -- rich==5.2.1
    -- attrs>=20.1.0

Usage Example for seleniumbase install chromedriver 84:

$ seleniumbase install chromedriver 84

*** chromedriver version for download = 84.0.4147.30 (Latest)

Downloading chromedriver_mac64.zip from:
https://chromedriver.storage.googleapis.com/84.0.4147.30/chromedriver_mac64.zip ...
Download Complete!

Extracting ['chromedriver'] from chromedriver_mac64.zip ...
Unzip Complete!

The file [chromedriver] was saved to:
/Users/michael/github/SeleniumBase/seleniumbase/drivers/chromedriver

Making [chromedriver 84.0.4147.30] executable ...
[chromedriver] is now ready for use!

Usage example for seleniumbase install edgedriver:

$ seleniumbase install edgedriver

*** edgedriver version for download = 84.0.522.61

Downloading edgedriver_mac64.zip from:
https://msedgedriver.azureedge.net/84.0.522.61/edgedriver_mac64.zip ...
Download Complete!

Extracting ['msedgedriver'] from edgedriver_mac64.zip ...
Unzip Complete!

The file [msedgedriver] was saved to:
/Users/michael/github/SeleniumBase/seleniumbase/drivers/msedgedriver

Making [msedgedriver 84.0.522.61] executable ...
[msedgedriver] is now ready for use!