File tree 19 files changed +90
-46
lines changed
main/java/com/udemy/spring/springselenium
test/java/com/udemy/spring/springselenium/googletest
19 files changed +90
-46
lines changed Original file line number Diff line number Diff line change
1
+ package com .udemy .spring .springselenium .kelvin .annotation ;
2
+
3
+ import org .springframework .beans .factory .annotation .Autowired ;
4
+ import org .springframework .context .annotation .Lazy ;
5
+
6
+ import java .lang .annotation .*;
7
+
8
+ @ Lazy
9
+ @ Autowired
10
+ @ Documented
11
+ @ Target ({ElementType .FIELD })
12
+ @ Retention (RetentionPolicy .RUNTIME )
13
+ public @interface LazyAutowired {
14
+ }
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .annotation ;
1
+ package com .udemy .spring .springselenium .kelvin . annotation ;
2
2
3
3
import org .springframework .context .annotation .Configuration ;
4
4
import org .springframework .context .annotation .Lazy ;
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .annotation ;
1
+ package com .udemy .spring .springselenium .kelvin . annotation ;
2
2
3
3
4
+ import org .springframework .beans .factory .config .ConfigurableBeanFactory ;
4
5
import org .springframework .context .annotation .Lazy ;
5
6
import org .springframework .context .annotation .Scope ;
6
7
import org .springframework .stereotype .Component ;
9
10
10
11
@ Lazy
11
12
@ Component
12
- @ Scope ("prototype" )
13
+ @ Scope (ConfigurableBeanFactory . SCOPE_PROTOTYPE )
13
14
@ Documented
14
15
@ Target ({ElementType .TYPE })
15
16
@ Retention (RetentionPolicy .RUNTIME )
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .annotation ;
1
+ package com .udemy .spring .springselenium .kelvin . annotation ;
2
2
3
3
import org .springframework .context .annotation .Lazy ;
4
4
import org .springframework .context .annotation .Scope ;
Original file line number Diff line number Diff line change
1
+ package com .udemy .spring .springselenium .kelvin .annotation ;
2
+
3
+ import org .springframework .context .annotation .Bean ;
4
+ import org .springframework .context .annotation .Scope ;
5
+
6
+ import java .lang .annotation .*;
7
+
8
+ @ Bean
9
+ @ Scope ("browserscope" )
10
+ @ Documented
11
+ @ Target ({ElementType .METHOD })
12
+ @ Retention (RetentionPolicy .RUNTIME )
13
+ public @interface ThreadScopeBean {
14
+ }
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .config ;
1
+ package com .udemy .spring .springselenium .kelvin . config ;
2
2
3
3
import com .github .javafaker .Faker ;
4
- import com .udemy .spring .springselenium .annotation .LazyConfiguration ;
4
+ import com .udemy .spring .springselenium .kelvin . annotation .LazyConfiguration ;
5
5
import org .springframework .context .annotation .Bean ;
6
6
7
7
@ LazyConfiguration
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .config ;
1
+ package com .udemy .spring .springselenium .kelvin . config ;
2
2
3
- import com .udemy .spring .springselenium .annotation .LazyConfiguration ;
3
+ import com .udemy .spring .springselenium .kelvin .annotation .LazyConfiguration ;
4
+ import com .udemy .spring .springselenium .kelvin .annotation .ThreadScopeBean ;
4
5
import org .openqa .selenium .WebDriver ;
5
6
import org .openqa .selenium .remote .DesiredCapabilities ;
6
7
import org .openqa .selenium .remote .RemoteWebDriver ;
7
8
import org .springframework .beans .factory .annotation .Value ;
8
9
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
9
10
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
10
- import org .springframework .context .annotation .Bean ;
11
11
import org .springframework .context .annotation .Profile ;
12
12
13
13
import java .net .URL ;
@@ -19,13 +19,13 @@ public class RemoteWebDriverConfig {
19
19
@ Value ("${selenium.grid.url}" )
20
20
private URL url ;
21
21
22
- @ Bean
22
+ @ ThreadScopeBean
23
23
@ ConditionalOnProperty (name = "browser" , havingValue = "firefox" )
24
24
public WebDriver remoteFirefoxDriver (){
25
25
return new RemoteWebDriver (this .url , DesiredCapabilities .firefox ());
26
26
}
27
27
28
- @ Bean
28
+ @ ThreadScopeBean
29
29
@ ConditionalOnMissingBean
30
30
public WebDriver remoteChromeDriver (){
31
31
return new RemoteWebDriver (this .url , DesiredCapabilities .chrome ());
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .config ;
1
+ package com .udemy .spring .springselenium .kelvin . config ;
2
2
3
- import com .udemy .spring .springselenium .annotation .LazyConfiguration ;
3
+ import com .udemy .spring .springselenium .kelvin .annotation .LazyConfiguration ;
4
+ import com .udemy .spring .springselenium .kelvin .annotation .ThreadScopeBean ;
4
5
import io .github .bonigarcia .wdm .WebDriverManager ;
5
6
import org .openqa .selenium .WebDriver ;
6
7
import org .openqa .selenium .chrome .ChromeDriver ;
7
8
import org .openqa .selenium .firefox .FirefoxDriver ;
8
9
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
9
10
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
10
- import org .springframework .context .annotation .Bean ;
11
11
import org .springframework .context .annotation .Profile ;
12
- import org .springframework .context .annotation .Scope ;
13
12
14
13
@ Profile ("!remote" )
15
14
@ LazyConfiguration
16
15
public class WebDriverConfig {
17
16
18
- @ Bean
17
+ @ ThreadScopeBean
19
18
@ ConditionalOnProperty (name = "browser" , havingValue = "firefox" )
20
19
public WebDriver firefoxDriver (){
21
20
WebDriverManager .firefoxdriver ().setup ();
22
21
return new FirefoxDriver ();
23
22
}
24
23
25
- @ Bean
26
- @ Scope ("browserscope" )
24
+ @ ThreadScopeBean
27
25
@ ConditionalOnMissingBean
28
26
public WebDriver chromeDriver (){
29
27
WebDriverManager .chromedriver ().version ("77.0.3865.40" ).setup ();
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .config ;
1
+ package com .udemy .spring .springselenium .kelvin . config ;
2
2
3
3
4
- import com .udemy .spring .springselenium .annotation .LazyConfiguration ;
4
+ import com .udemy .spring .springselenium .kelvin . annotation .LazyConfiguration ;
5
5
import org .openqa .selenium .WebDriver ;
6
6
import org .openqa .selenium .support .ui .WebDriverWait ;
7
7
import org .springframework .beans .factory .annotation .Value ;
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .config ;
1
+ package com .udemy .spring .springselenium .kelvin . scope ;
2
2
3
3
import org .openqa .selenium .remote .RemoteWebDriver ;
4
4
import org .openqa .selenium .remote .SessionId ;
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .config ;
1
+ package com .udemy .spring .springselenium .kelvin . scope ;
2
2
3
3
import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
4
4
import org .springframework .context .annotation .Bean ;
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .config ;
1
+ package com .udemy .spring .springselenium .kelvin . scope ;
2
2
3
3
import org .springframework .beans .BeansException ;
4
4
import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
Original file line number Diff line number Diff line change 1
- package com .udemy .spring .springselenium .util ;
1
+ package com .udemy .spring .springselenium .kelvin . service ;
2
2
3
3
import com .github .javafaker .Faker ;
4
4
import org .openqa .selenium .OutputType ;
7
7
import org .springframework .beans .factory .annotation .Value ;
8
8
import org .springframework .context .ApplicationContext ;
9
9
import org .springframework .context .annotation .Lazy ;
10
- import org .springframework .stereotype .Component ;
10
+ import org .springframework .stereotype .Service ;
11
11
import org .springframework .util .FileCopyUtils ;
12
12
13
13
import java .io .File ;
14
14
import java .io .IOException ;
15
15
import java .nio .file .Path ;
16
16
17
17
@ Lazy
18
- @ Component
19
- public class ScreenShotUtil {
18
+ @ Service
19
+ public class ScreenshotService {
20
20
21
21
@ Autowired
22
22
private ApplicationContext ctx ;
Original file line number Diff line number Diff line change 1
1
package com .udemy .spring .springselenium .page .google ;
2
2
3
- import com .udemy .spring .springselenium .annotation .Page ;
3
+ import com .udemy .spring .springselenium .kelvin . annotation .Page ;
4
4
import com .udemy .spring .springselenium .page .Base ;
5
5
import org .springframework .beans .factory .annotation .Autowired ;
6
6
import org .springframework .beans .factory .annotation .Value ;
Original file line number Diff line number Diff line change 1
1
package com .udemy .spring .springselenium .page .google ;
2
2
3
- import com .udemy .spring .springselenium .annotation .PageFragment ;
3
+ import com .udemy .spring .springselenium .kelvin . annotation .PageFragment ;
4
4
import com .udemy .spring .springselenium .page .Base ;
5
5
import org .openqa .selenium .WebElement ;
6
6
import org .openqa .selenium .support .FindBy ;
Original file line number Diff line number Diff line change 1
1
package com .udemy .spring .springselenium .page .google ;
2
2
3
- import com .udemy .spring .springselenium .annotation .PageFragment ;
3
+ import com .udemy .spring .springselenium .kelvin . annotation .PageFragment ;
4
4
import com .udemy .spring .springselenium .page .Base ;
5
5
import org .openqa .selenium .WebElement ;
6
6
import org .openqa .selenium .support .FindBy ;
Original file line number Diff line number Diff line change 1
1
package com .udemy .spring .springselenium .googletest ;
2
2
3
3
import com .udemy .spring .springselenium .SpringBaseTestNGTest ;
4
+ import com .udemy .spring .springselenium .kelvin .annotation .LazyAutowired ;
5
+ import com .udemy .spring .springselenium .kelvin .service .ScreenshotService ;
4
6
import com .udemy .spring .springselenium .page .google .GooglePage ;
5
- import com .udemy .spring .springselenium .util .ScreenShotUtil ;
6
- import org .springframework .beans .factory .annotation .Autowired ;
7
- import org .springframework .context .annotation .Lazy ;
8
7
import org .testng .Assert ;
9
8
import org .testng .annotations .Test ;
10
9
11
10
import java .io .IOException ;
12
11
13
12
public class Google1Test extends SpringBaseTestNGTest {
14
13
15
- @ Autowired
14
+ @ LazyAutowired
16
15
private GooglePage googlePage ;
17
16
18
- @ Lazy
19
- @ Autowired
20
- private ScreenShotUtil screenShotUtil ;
17
+ @ LazyAutowired
18
+ private ScreenshotService screenshotService ;
21
19
22
20
@ Test
23
21
public void googleTest () throws IOException {
@@ -26,7 +24,7 @@ public void googleTest() throws IOException {
26
24
this .googlePage .getSearchComponent ().search ("spring boot" );
27
25
Assert .assertTrue (this .googlePage .getSearchResult ().isAt ());
28
26
Assert .assertTrue (this .googlePage .getSearchResult ().getCount () > 2 );
29
- this .screenShotUtil .takeScreenShot ();
27
+ this .screenshotService .takeScreenShot ();
30
28
this .googlePage .close ();
31
29
}
32
30
Original file line number Diff line number Diff line change 1
1
package com .udemy .spring .springselenium .googletest ;
2
2
3
3
import com .udemy .spring .springselenium .SpringBaseTestNGTest ;
4
+ import com .udemy .spring .springselenium .kelvin .annotation .LazyAutowired ;
5
+ import com .udemy .spring .springselenium .kelvin .service .ScreenshotService ;
4
6
import com .udemy .spring .springselenium .page .google .GooglePage ;
5
- import com .udemy .spring .springselenium .util .ScreenShotUtil ;
6
- import org .springframework .beans .factory .annotation .Autowired ;
7
- import org .springframework .context .annotation .Lazy ;
8
7
import org .testng .Assert ;
9
8
import org .testng .annotations .Test ;
10
9
11
10
import java .io .IOException ;
12
11
13
12
public class Google2Test extends SpringBaseTestNGTest {
14
13
15
- @ Autowired
14
+ @ LazyAutowired
16
15
private GooglePage googlePage ;
17
16
18
- @ Lazy
19
- @ Autowired
20
- private ScreenShotUtil screenShotUtil ;
17
+ @ LazyAutowired
18
+ private ScreenshotService screenshotService ;
21
19
22
20
@ Test
23
21
public void googleTest () throws IOException {
@@ -26,7 +24,7 @@ public void googleTest() throws IOException {
26
24
this .googlePage .getSearchComponent ().search ("selenium" );
27
25
Assert .assertTrue (this .googlePage .getSearchResult ().isAt ());
28
26
Assert .assertTrue (this .googlePage .getSearchResult ().getCount () > 2 );
29
- this .screenShotUtil .takeScreenShot ();
27
+ this .screenshotService .takeScreenShot ();
30
28
this .googlePage .close ();
31
29
}
32
30
Original file line number Diff line number Diff line change
1
+ package com .udemy .spring .springselenium .googletest ;
2
+
3
+ import com .udemy .spring .springselenium .SpringBaseTestNGTest ;
4
+ import org .openqa .selenium .WebDriver ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .context .ApplicationContext ;
7
+ import org .testng .annotations .Test ;
8
+
9
+ public class MultiBrowserTest extends SpringBaseTestNGTest {
10
+
11
+ @ Autowired
12
+ private ApplicationContext ctx ;
13
+
14
+ @ Test
15
+ public void browserTest (){
16
+ this .ctx .getBean ("chromeDriver" , WebDriver .class ).get ("https://www.google.com" );
17
+ this .ctx .getBean ("firefoxDriver" , WebDriver .class ).get ("https://www.yahoo.com" );
18
+ }
19
+
20
+
21
+ }
You can’t perform that action at this time.
0 commit comments