selenium +IntelliJ+firefox/chrome 环境全套搭配

1第一步:下载IntelliJ idea 代码编辑器

2第二步:下载浏览器Chrome

3第三步:下载JDK

4第四步:配置环境变量(1JAVA_HOME 2 path)

5第五步:下载Maven

6第六步:配置环境变量(1MAVEN_HOME 2path)

7第七步:下载与浏览器版本匹配的ChromeDriver

8第八步: 在 Idea里面设置 JDK , Maven

9 第九步:创建工程 project

10 第十步:pom.xml文件中写依赖(1 需要什么包去maven仓库下载依赖,拿整个dependancy 2在工程中terminal中执行 mvn clean install命令,并去maven块刷新工程和包)

11.drive

【笔记】chromedriver下载与安装方法_谷歌驱动_逸峰轻云的博客-CSDN博客

cucumebr:

Cucumber&selenium学习--工程搭建_cucumber和selenium 依赖-CSDN博客

自动化测试实战:Cucumber+Selenium测试场景应用 - 知乎

idea kubernetes插件 配置 idea cucumber插件_mob6454cc780924的技术博客_51CTO博客

Junit:

idea插件完成junit代码生成,和springboot代码示例_junitgenerator_weisian151的博客-CSDN博客

注意事项:

1 Runner文件写在test目录下

2 maven文件下conf文件夹下的settings.xml 加阿里云镜像

<mirror>

<id>alimaven</id>

<name>aliyun maven</name>

<url>http://maven.aliyun.com/nexus/content/groups/public/</url>

<mirrorOf>central</mirrorOf>

</mirror>

3 配置maven本地仓库

<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>org.example</groupId>
  <artifactId>JSCTesting</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>JSCTesting</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <logging.verson>1.2</logging.verson>
    <selenium.version>4.13.0</selenium.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-resources-plugin</artifactId>
      <version>2.4.3</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>${logging.verson}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>${selenium.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-api</artifactId>
      <version>${selenium.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-chrome-driver</artifactId>
      <version>4.13.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-firefox-driver</artifactId>
      <version>4.13.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.5.2</version>
    </dependency>
    <dependency>
      <groupId>com.aventstack</groupId>
      <artifactId>extentreports</artifactId>
      <version>3.0.6</version>
    </dependency>

    <dependency>
      <groupId>org.dom4j</groupId>
      <artifactId>dom4j</artifactId>
      <version>2.0.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/log4j/log4j -->
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/commons-email/commons-email -->
    <dependency>
      <groupId>commons-email</groupId>
      <artifactId>commons-email</artifactId>
      <version>1.1</version>
    </dependency>

    <dependency>
      <groupId>org.uncommons</groupId>
      <artifactId>reportng</artifactId>
      <version>1.1.4</version>
    </dependency>


    <!--report -->
   <dependency>
     <groupId>net.masterthought</groupId>
     <artifactId>cucumber-reporting</artifactId>
     <version>5.6.1</version>
   </dependency>
    <!-- report  -->
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.8.6</version>
    </dependency>
    <!-- Junit -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>
    <!--  cucumber dependency  -->
     <dependency>
       <groupId>io.cucumber</groupId>
       <artifactId>cucumber-junit</artifactId>
       <version>7.14.0</version>
     </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>7.14.0</version>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-gherkin</artifactId>
      <version>7.14.0</version>
    </dependency>

  </dependencies>
 </project>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Chrome Options是SeleniumChrome浏览器的一种参数配置选项。它允许我们在启动Chrome浏览器时设置各种选项,以实现不同的需求。 使用Chrome Options,我们可以完成以下任务: 1. 设置浏览器的浏览模式:我们可以通过设置"--headless"参数来启动Chrome无头模式,即在没有显示浏览器界面的情况下运行浏览器,这对于执行自动化测试很有用。 2. 设置浏览器的User-Agent:通过设置"--user-agent"参数,我们可以改变浏览器的User-Agent,以模拟不同的浏览器和设备。 3. 设置浏览器的下载路径:我们可以使用"--download.default_directory"参数来设置下载文件的默认保存路径。 4. 设置浏览器的语言:通过设置"--lang"参数,我们可以改变浏览器的语言环境,使其适应不同语言的网站。 5. 启用或禁用浏览器的扩展:通过设置"--disable-extensions"参数,我们可以禁用浏览器的扩展,或者通过"--load-extension"参数加载指定的扩展。 为了使用Chrome Options,我们首先需要导入selenium包中的Options类: ```python from selenium.webdriver.chrome.options import Options ``` 然后,我们可以创建Options对象,并设置所需的参数: ```python options = Options() options.add_argument("--headless") options.add_argument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3") options.add_argument("--download.default_directory=C:/Downloads") ``` 最后,将Options对象作为参数传递给ChromeDriver的构造函数,即可在启动Chrome浏览器时应用这些参数配置: ```python driver = webdriver.Chrome(chrome_options=options) ``` 通过这种方式,我们可以充分利用Chrome Options的各种参数,对Chrome浏览器进行个性化设置,以满足我们不同场景下的需求。 ### 回答2: Python Selenium库提供了一些Chrome Options参数,可以在使用Chrome浏览器自动化测试时进行配置。下面是一些常用的Options参数及其用法: 1. --headless:设置无头模式,即在后台运行浏览器而不显示图形界面。可以提高测试效率,并节省计算资源。 2. --disable-gpu:禁用GPU加速。有些时候,GPU加速可能导致浏览器无法正常工作,禁用它可以解决一些兼容性问题。 3. --disable-extensions:禁用浏览器扩展程序。有些扩展程序可能会干扰自动化测试的进行,禁用它们可以提高测试的稳定性。 4. --disable-infobars:禁用浏览器顶部的信息栏。有些站点可能会通过弹出信息栏来干扰测试过程,禁用它可以避免干扰。 5. --start-maximized:启动时最大化浏览器窗口。默认情况下,启动时浏览器窗口是最小化的,通过设置这个参数可以让窗口最大化,方便观察测试过程。 6. --lang=xxx:设置浏览器的语言。有些站点的内容可能根据语言设置而变化,可以通过设置这个参数来模拟不同的语言环境。 以上只是常用的一些Options参数,实际上还有很多其他参数可以用来控制浏览器的行为。通过结合这些参数的使用,可以更加灵活地进行自动化测试,满足不同测试需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值