Skip to content

Make improvements to the smart-word-wrap code #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 23, 2020

Conversation

mdmintz
Copy link
Member

@mdmintz mdmintz commented Aug 23, 2020

Make improvements to the smart-word-wrap code

  • 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.)

@mdmintz mdmintz merged commit b02e820 into master Aug 23, 2020
@mdmintz mdmintz deleted the smart-word-wrap-improvements branch August 23, 2020 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant