简体   繁体   English

如何在 jenkins 中使用真实浏览器运行 selenium 脚本

[英]how to run selenium script with real browser in jenkins

I am running selenium scripts in Jenkins and it is showing console output without opening any real browser like Mozilla/Chrome/IE.我在 Jenkins 中运行 selenium 脚本,它显示控制台输出,而无需打开任何真正的浏览器,如 Mozilla/Chrome/IE。

I want to run the scripts using a real browser and want to see what is happening UI.我想使用真实的浏览器运行脚本,并想看看 UI 发生了什么。

Is there any plug in need to install in Jenkins? Jenkins 中是否需要安装任何插件? or any code required to add?或需要添加任何代码? or any services need to modify/restart/any operation?或任何服务需要修改/重启/任何操作?

Please suggest me if there is any solution or any website providing the information.如果有任何解决方案或任何提供信息的网站,请建议我。 Thank you谢谢

The problem is you are using Jenkins window installer which is working as service in Windows.问题是您正在使用 Jenkins 窗口安装程序,它在 Windows 中作为服务运行。 In Windows Services are not allowed for UI invocation/execution.在 Windows 服务中不允许 UI 调用/执行。

You need to use jenkins.war and run it using a cmd which is executed as "run as admin"您需要使用 jenkins.war 并使用作为“以管理员身份运行”执行的 cmd 运行它

Download war from below URL :-从以下网址下载战争:-

https://updates.jenkins-ci.org/download/war/ https://updates.jenkins-ci.org/download/war/

https://jenkins.io/download/ https://jenkins.io/download/

Use the following command at command prompt:在命令提示符下使用以下命令:

java -jar jenkins.war --httpPort=9090

If you want to use https use the following command:如果要使用 https,请使用以下命令:

java -jar jenkins.war --httpsPort=9090

You can change the port number as per your need in above command您可以根据需要在上述命令中更改端口号

Now go to any browser and hit现在转到任何浏览器并点击

localhost:9090

You can try below steps to run selenium scripts on real browser in your local machine or any server that supports browser ... from Jenkins.您可以尝试以下步骤在本地机器或任何支持浏览器的服务器上的真实浏览器上运行 selenium 脚本......来自 Jenkins。

  • Convert your selenium project to maven project.将您的 selenium 项目转换为 Maven 项目。
  • Add dependency for all the jars required in pom.xml为 pom.xml 中所需的所有 jar 添加依赖项
  • Add plugins in pom在pom中添加插件

     <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> <inherited>true</inherited> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> </plugins>
  • Change run configuration--> under Test --> suite --> set location 0f testng.xml eg :D:\\\\testng.xml更改运行配置--> 在测试下 --> 套件 --> 设置位置 0f testng.xml 例如 :D:\\\\testng.xml

  • Open Jenkins(for installing Jenkins, you can follow any thread to install Jenkins).打开 Jenkins(安装 Jenkins,可以按照任何线程安装 Jenkins)。

  • Install maven plugin in Jenkins and create a maven project under BUILD input pom.xml path in ROOT POM eg :Root POM -- > D:\\\\pom.xml and under goals provide clean test.在 Jenkins 中安装 maven 插件并在 ROOT POM 中的 BUILD 输入 pom.xml 路径下创建一个 maven 项目,例如 :Root POM --> D:\\\\pom.xml 并在目标下提供干净的测试。
  • Save and click on Build Now :)保存并点击立即构建:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM