Skip to content

Commit 20c33a2

Browse files
author
japneet
committed
first playwright commit
0 parents  commit 20c33a2

File tree

15 files changed

+337
-0
lines changed

15 files changed

+337
-0
lines changed

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>PlaywrightFramework</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<name>PlaywrightFramework</name>
12+
<!-- FIXME change it to the project's website -->
13+
<url>http://www.example.com</url>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>1.7</maven.compiler.source>
18+
<maven.compiler.target>1.7</maven.compiler.target>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<version>4.11</version>
26+
<scope>test</scope>
27+
</dependency>
28+
29+
<!-- https://mvnrepository.com/artifact/com.microsoft.playwright/playwright -->
30+
<dependency>
31+
<groupId>com.microsoft.playwright</groupId>
32+
<artifactId>playwright</artifactId>
33+
<version>1.28.1</version>
34+
</dependency>
35+
36+
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
37+
<dependency>
38+
<groupId>org.testng</groupId>
39+
<artifactId>testng</artifactId>
40+
<version>6.14.3</version>
41+
<scope>test</scope>
42+
</dependency>
43+
44+
45+
</dependencies>
46+
47+
<build>
48+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
49+
<plugins>
50+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
51+
<plugin>
52+
<artifactId>maven-clean-plugin</artifactId>
53+
<version>3.1.0</version>
54+
</plugin>
55+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
56+
<plugin>
57+
<artifactId>maven-resources-plugin</artifactId>
58+
<version>3.0.2</version>
59+
</plugin>
60+
<plugin>
61+
<artifactId>maven-compiler-plugin</artifactId>
62+
<version>3.8.0</version>
63+
</plugin>
64+
<plugin>
65+
<artifactId>maven-surefire-plugin</artifactId>
66+
<version>2.22.1</version>
67+
</plugin>
68+
<plugin>
69+
<artifactId>maven-jar-plugin</artifactId>
70+
<version>3.0.2</version>
71+
</plugin>
72+
<plugin>
73+
<artifactId>maven-install-plugin</artifactId>
74+
<version>2.5.2</version>
75+
</plugin>
76+
<plugin>
77+
<artifactId>maven-deploy-plugin</artifactId>
78+
<version>2.8.2</version>
79+
</plugin>
80+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
81+
<plugin>
82+
<artifactId>maven-site-plugin</artifactId>
83+
<version>3.7.1</version>
84+
</plugin>
85+
<plugin>
86+
<artifactId>maven-project-info-reports-plugin</artifactId>
87+
<version>3.0.0</version>
88+
</plugin>
89+
</plugins>
90+
</pluginManagement>
91+
<plugins>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-compiler-plugin</artifactId>
95+
<configuration>
96+
<source>8</source>
97+
<target>8</target>
98+
</configuration>
99+
</plugin>
100+
</plugins>
101+
</build>
102+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package factory;
2+
3+
import com.microsoft.playwright.*;
4+
5+
public class PlaywrightFactory
6+
{
7+
Playwright playwright;
8+
Browser browser;
9+
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
10+
BrowserContext context;
11+
Page page;
12+
13+
public Page initBrowser (String browserName)
14+
{
15+
System.out.println("Browser name is: "+browserName);
16+
playwright = Playwright.create();
17+
18+
if(browserName.equalsIgnoreCase("chromium"))
19+
{
20+
browser = playwright.chromium().launch(launchOptions.setHeadless(false));
21+
22+
} else if(browserName.equalsIgnoreCase("firefox"))
23+
{
24+
browser = playwright.firefox().launch(launchOptions.setHeadless(false));
25+
26+
} else if (browserName.equalsIgnoreCase("safari"))
27+
{
28+
browser = playwright.webkit().launch(launchOptions.setHeadless(false));
29+
30+
} else if (browserName.equalsIgnoreCase("chrome"))
31+
{
32+
browser = playwright.chromium().launch(launchOptions.setChannel("chrome").setHeadless(false));
33+
34+
} else
35+
{
36+
System.out.println("browser not supported!!");
37+
}
38+
39+
context = browser.newContext();
40+
page = context.newPage();
41+
page.navigate("https://naveenautomationlabs.com/opencart/");
42+
43+
return page;
44+
45+
}
46+
}

src/main/java/pages/HomePage.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package pages;
2+
3+
import com.microsoft.playwright.Page;
4+
5+
public class HomePage
6+
{
7+
//constants
8+
private Page page;
9+
10+
//String locators - OR
11+
private String searchBar = "//input[@name='search']";
12+
private String searchBtn = "(//input[@name='search']//following::button)[1]";
13+
private String searchedItemName = "//h1";
14+
15+
16+
//Constructor to capture Page
17+
public HomePage(Page page)
18+
{
19+
this.page = page;
20+
}
21+
22+
public String getPageTitle()
23+
{
24+
return page.title();
25+
}
26+
27+
public String getPageUrl()
28+
{
29+
return page.url();
30+
}
31+
32+
public String searchItem(String itemToBeSearched)
33+
{
34+
page.fill(searchBar, itemToBeSearched);
35+
page.click(searchBtn);
36+
String itemName = page.textContent(searchedItemName);
37+
return itemName;
38+
}
39+
40+
41+
}

src/test/java/base/BaseTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package base;
2+
3+
import com.microsoft.playwright.Page;
4+
import factory.PlaywrightFactory;
5+
import org.testng.annotations.AfterTest;
6+
import org.testng.annotations.BeforeMethod;
7+
import org.testng.annotations.BeforeTest;
8+
9+
public class BaseTest
10+
{
11+
PlaywrightFactory factory;
12+
protected Page page;
13+
14+
@BeforeTest
15+
public void setupPlaywright()
16+
{
17+
factory = new PlaywrightFactory();
18+
page = factory.initBrowser("chrome");
19+
}
20+
21+
@AfterTest
22+
public void tearDownPlaywright()
23+
{
24+
page.context().browser().close();
25+
}
26+
27+
}

0 commit comments

Comments
 (0)