-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Md Shahnewaz Zaman
authored
Feb 7, 2023
1 parent
661e1d9
commit e5a0121
Showing
11 changed files
with
382 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Architecture: Selenium uses the WebDriver API to interact between web browsers and browser drivers. It operates by translating test cases into JSON and sending them to the browsers, which then execute the commands and send an HTTP response back. | ||
Architecture: Playwright uses a WebSocket connection rather than the WebDriver API and HTTP. This stays open for the duration of the test, so everything is sent on one connection. This is one reason why Playwright’s execution speeds tend to be faster. | ||
|
||
## Setup Allure result | ||
``` | ||
Pre-configure | ||
- Folow the instruction from the website - https://docs.qameta.io/allure/#_testng | ||
- Set up POM File | ||
``` | ||
``` | ||
- Navigate to the URL - https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/ | ||
- Click on the download latest version like: 2.20.1 | ||
- Download zip file | ||
- Extract it | ||
- Set up environment variable upto bin folder | ||
``` | ||
|
||
``` | ||
- Open up the terminal | ||
- > allure --version (version should be available) | ||
- > allure serve allure-result (Result will open on the browser) | ||
``` | ||
|
||
## Run/Execute the test suite | ||
``` | ||
- On the test case click run play button or right click on the class file and click on run test | ||
- Right click on the testNG.xml file and clcik on run test | ||
- open up the terminal and type > mvn clean test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.insight.javaBoilerplate</groupId> | ||
<artifactId>javaBoilerplate</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>javaBoilerplate</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<aspectj.version>1.9.19</aspectj.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<playwright.version>1.28.1</playwright.version> | ||
<testng.version>7.7.1</testng.version> | ||
<allure.testng.version>2.20.0</allure.testng.version> | ||
<allure.rest-assured.version>2.14.0</allure.rest-assured.version> | ||
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> | ||
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.microsoft.playwright</groupId> | ||
<artifactId>playwright</artifactId> | ||
<version>${playwright.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<version>${testng.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.qameta.allure</groupId> | ||
<artifactId>allure-testng</artifactId> | ||
<version>${allure.testng.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<!-- Compiler plug-in --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven-compiler-plugin.version}</version> | ||
<configuration> | ||
<fork>true</fork> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<!-- Below plug-in is used to execute tests --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${maven-surefire-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>integration-test</phase> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
<configuration> | ||
<testFailureIgnore>true</testFailureIgnore> | ||
<suiteXmlFiles> | ||
<suiteXmlFile>testNGSuite.xml</suiteXmlFile> | ||
</suiteXmlFiles> | ||
<argLine> | ||
-javaagent:"${settings.localRepository}\org\aspectj\aspectjweaver\${aspectj.version}\aspectjweaver-${aspectj.version}.jar" | ||
</argLine> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjweaver</artifactId> | ||
<version>${aspectj.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
javaBoilerplate/src/main/java/com/insight/javaBoilerplate/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.insight.javaBoilerplate; | ||
|
||
/** | ||
* Hello world! | ||
* | ||
*/ | ||
public class App | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
System.out.println( "Hello World!" ); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
javaBoilerplate/src/test/java/com/insight/javaBoilerplate/pageObjects/BasePage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.insight.javaBoilerplate.pageObjects; | ||
|
||
import com.microsoft.playwright.Page; | ||
|
||
public class BasePage { | ||
|
||
public static Page page; | ||
|
||
public BasePage(Page page){ | ||
this.page = page; | ||
} | ||
public void click(String locator){ | ||
page.click(locator); | ||
} | ||
public void fill(String locator, String value){ | ||
page.fill(locator, value); | ||
} | ||
public void mouseHover(String locator){ | ||
page.hover(locator); | ||
|
||
} | ||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
javaBoilerplate/src/test/java/com/insight/javaBoilerplate/pageObjects/LoginPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.insight.javaBoilerplate.pageObjects; | ||
|
||
import com.microsoft.playwright.Page; | ||
|
||
public class LoginPage extends BasePage{ | ||
public LoginPage(Page page) { | ||
super(page); | ||
} | ||
|
||
String abTesting = "a[href='/abtest']"; | ||
String addRemoveElement = "a[href='/add_remove_elements/']"; | ||
String BasicAuth = "a[href='/basic_auth']"; | ||
|
||
public String getAbTesting() { | ||
return abTesting; | ||
} | ||
|
||
public String getAddRemoveElement() { | ||
return addRemoveElement; | ||
} | ||
|
||
public String getBasicAuth() { | ||
return BasicAuth; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
javaBoilerplate/src/test/java/com/insight/javaBoilerplate/testCases/BaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.insight.javaBoilerplate.testCases; | ||
|
||
import com.microsoft.playwright.Browser; | ||
import com.microsoft.playwright.BrowserType; | ||
import com.microsoft.playwright.Page; | ||
import com.microsoft.playwright.Playwright; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.BeforeSuite; | ||
|
||
public class BaseTest { | ||
|
||
private Playwright playwright; | ||
public Browser browser; | ||
public Page page; | ||
|
||
@BeforeClass | ||
public void setUp(){ | ||
System.out.println("Log file configuration goes here"); | ||
System.out.println("Database configuration goes here"); | ||
} | ||
|
||
public Browser getBrowser(String browserName) { | ||
playwright = Playwright.create(); | ||
switch (browserName) { | ||
case "chrome": | ||
return playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel("chrome").setHeadless(false)); | ||
case "headless": | ||
return playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false)); | ||
case "firefox": | ||
return playwright.firefox().launch(new BrowserType.LaunchOptions().setChannel("firefox").setHeadless(false)); | ||
case "webkit": | ||
return playwright.webkit().launch(new BrowserType.LaunchOptions().setHeadless(false)); | ||
default: | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
public void navigate(Browser browser, String url){ | ||
this.browser = browser; | ||
page = this.browser.newPage(); | ||
page.navigate(url); | ||
} | ||
@AfterMethod | ||
public void quit(){ | ||
browser.close(); | ||
page.close(); | ||
playwright.close(); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
javaBoilerplate/src/test/java/com/insight/javaBoilerplate/testCases/LaunchTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.insight.javaBoilerplate.testCases; | ||
|
||
import com.microsoft.playwright.*; | ||
import org.testng.annotations.Test; | ||
|
||
import java.awt.*; | ||
import java.nio.file.Paths; | ||
|
||
public class LaunchTest | ||
{ | ||
@Test | ||
public void playwrightTest() | ||
{ | ||
|
||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | ||
double width = screenSize.getWidth(); | ||
double height = screenSize.getHeight(); | ||
|
||
Playwright playwright = Playwright.create(); | ||
//.setSlowMo(50)); | ||
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false)); | ||
//Without private mode | ||
// BrowserContext browserContext = playwright.chromium().launchPersistentContext(Paths.get(""), new BrowserType.LaunchPersistentContextOptions().setHeadless(false)); | ||
// Set browser executable path | ||
// Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false).setExecutablePath(Paths.get("chrome.exe/msedge.exe/firefox.exe"))); | ||
// Browser set edge | ||
// Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel("msedge").setHeadless(false)); | ||
// Chrome | ||
// Browser browser = playwright.firefox().launch(new BrowserType.LaunchOptions().setHeadless(false)); | ||
// Firefox | ||
// Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel("chrome").setHeadless(false)); | ||
// Maximizing Browser | ||
// BrowserContext browserContext = browser.newContext(new Browser.NewContextOptions().setViewportSize((int)width, (int)height)); | ||
|
||
// Simple way to maximize | ||
// ArrayList<String> argument = new ArrayList<>(); | ||
// argument.add("--start-maximized"); | ||
// Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel("chrome").setHeadless(false).setArgs(argument)); | ||
// BrowserContext browserContext = browser.newContext(new Browser.NewContextOptions().setViewportSize(null)); | ||
|
||
Page page = browser.newPage(); | ||
page.navigate("https://reqres.in/"); | ||
System.out.println(page.title()); | ||
|
||
page.close(); | ||
playwright.close(); | ||
|
||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
javaBoilerplate/src/test/java/com/insight/javaBoilerplate/testCases/LoginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.insight.javaBoilerplate.testCases; | ||
|
||
import com.insight.javaBoilerplate.pageObjects.LoginPage; | ||
import com.insight.javaBoilerplate.utilities.Data; | ||
import com.microsoft.playwright.Browser; | ||
import org.testng.annotations.Test; | ||
|
||
public class LoginTest extends BaseTest{ | ||
@Test | ||
public void loginTest() throws InterruptedException { | ||
Browser browser = getBrowser(Data.CHROME); | ||
navigate(browser, Data.URL); | ||
|
||
LoginPage loginPage = new LoginPage(page); | ||
loginPage.click(loginPage.getAbTesting()); | ||
Thread.sleep(1000); | ||
page.goBack(); | ||
Thread.sleep(1000); | ||
loginPage.click(loginPage.getAddRemoveElement()); | ||
Thread.sleep(1000); | ||
page.goBack(); | ||
Thread.sleep(1000); | ||
loginPage.click(loginPage.getBasicAuth()); | ||
Thread.sleep(1000); | ||
page.goBack(); | ||
Thread.sleep(1000); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
javaBoilerplate/src/test/java/com/insight/javaBoilerplate/testCases/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.insight.javaBoilerplate.testCases; | ||
|
||
import com.microsoft.playwright.Browser; | ||
import com.microsoft.playwright.BrowserType; | ||
import com.microsoft.playwright.Page; | ||
import com.microsoft.playwright.Playwright; | ||
|
||
import java.awt.*; | ||
|
||
public class Test | ||
{ | ||
@org.testng.annotations.Test | ||
public void playwrightTest() | ||
{ | ||
|
||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | ||
double width = screenSize.getWidth(); | ||
double height = screenSize.getHeight(); | ||
|
||
Playwright playwright = Playwright.create(); | ||
//.setSlowMo(50)); | ||
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false)); | ||
// Browser set edge | ||
// Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel("msedge").setHeadless(false)); | ||
// Chrome | ||
// Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel("chrome").setHeadless(false)); | ||
// Maximizing Browser | ||
// BrowserContext browserContext = browser.newContext(new Browser.NewContextOptions().setViewportSize((int)width, (int)height)); | ||
|
||
// Simple way to maximize | ||
// ArrayList<String> argument = new ArrayList<>(); | ||
// argument.add("--start-maximized"); | ||
// Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel("chrome").setHeadless(false).setArgs(argument)); | ||
// BrowserContext browserContext = browser.newContext(new Browser.NewContextOptions().setViewportSize(null)); | ||
|
||
Page page = browser.newPage(); | ||
page.navigate("https://reqres.in/"); | ||
System.out.println(page.title()); | ||
|
||
page.close(); | ||
playwright.close(); | ||
|
||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
javaBoilerplate/src/test/java/com/insight/javaBoilerplate/utilities/Data.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.insight.javaBoilerplate.utilities; | ||
|
||
public class Data { | ||
|
||
public static final String URL = "https://the-internet.herokuapp.com/"; | ||
public static final String FIREFOX = "firefox"; | ||
public static final String CHROME = "chrome"; | ||
public static final String WEBKIT = "webkit"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" > | ||
|
||
<suite name="rigorousTest" verbose="1" > | ||
<test name="rigorousTest" > | ||
<parameter name="browser" value="chrome"/> | ||
<parameter name="username" value="tomsmith"/> | ||
<parameter name="password" value="SuperSecretPassword!"/> | ||
<parameter name="wrongPassword" value="SuperSecretPassword"/> | ||
<classes> | ||
<class name="com.insight.javaBoilerplate.testCases.LoginTest" /> | ||
</classes> | ||
</test> | ||
</suite> |