Skip to content

Commit

Permalink
- update
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanAksionau committed Aug 2, 2023
1 parent e02d384 commit b79ece2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Remote execution on Selenium grid
- Run command ```docker-compose up -d --scale chrome=4``` to start selenium hub and 4 chrome nodes.
- Go to http://localhost:4444/grid/console to check 'Grid Console'.
- To activate settings you should specify required 'properties' files for spring configuration - ```spring.profiles.active=prod,remote```
- You can also run tests from maven itself with ```mvn clean install -D"spring.profiles.active=prod,remote"``` command.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.*;

import java.net.URL;
import java.time.Duration;
Expand All @@ -21,9 +18,11 @@
* which will use set property, locate into predefined '.properties' file (ex. 'browser=chrome').
* <p>
* In order to specify which '.properties' file,
* we are gonna to use, we specify properties file marker like {@code @Profile("remote")},
* so 'application-remote.properties' will be selected by Spring framework for usage.
* we specify properties file marker like {@code @Profile("remote")},
* so 'application-remote.properties' will be selected by Spring framework for usage,
* otherwise it avoids to initiate this configuration.
*/
@Lazy
@Configuration
@Profile("remote")
public class RemoteWebDriverFactory {
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/com/ea/springbasic/driver/WebDriverFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.*;

import java.time.Duration;
import java.util.List;
Expand All @@ -26,6 +23,7 @@
* Also, to support parallel test execution we add @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) annotation
* for all page object classes. See ex. {@link com.ea.springbasic.pages.HomePage} class.
*/
@Lazy
@Configuration
@Profile("!remote")
public class WebDriverFactory {
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/ea/springbasic/pages/BasePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;

import java.time.Duration;

Expand All @@ -13,6 +14,7 @@ public abstract class BasePage {
@Autowired
protected WebDriver webDriver;

@Lazy
@Autowired
protected WebDriverWait wait;

Expand Down
3 changes: 3 additions & 0 deletions src/test/java/com/ea/springbasic/test/SpringTestNGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Lazy;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.*;

Expand All @@ -24,6 +25,7 @@ public class SpringTestNGTest extends AbstractTestNGSpringContextTests {
@Autowired
private MainPage2 mainPage2;

@Lazy
@Autowired
private ScreenShotUtil screenShotUtil;

Expand All @@ -42,6 +44,7 @@ protected void springTestContextPrepareTestInstance() throws Exception {
@Test
public void test() {
mainPage2.performLogin();
mainPage2.isDisplayed();
screenShotUtil.takeScreenShot();
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/ea/springbasic/util/ScreenShotUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.UUID;

@Lazy
@Component
public class ScreenShotUtil {

Expand Down

0 comments on commit b79ece2

Please sign in to comment.